0

I'm trying to use *ngFor to generate a table that is collapsible. Doing this though requires a unique id matching both the tr element with the data-target attribute for the collapsible to work. My plan is to use the User's ID from the backend as this unique identifier. I can't seem to find the correct syntax for this.

Below is the code I've tried, but I know this isn't the correct syntax. the "data-target" attribute is what I need the help with.

<table class="table table-condensed table-striped">
          <thead>
            <tr>
              <th></th>
              <th>Fist Name</th>
              <th>Last Name</th>
            </tr>
          </thead>

          <tbody>
            <tr
              data-toggle="collapse"
              data-target="#demo[[user.id]]"
              class="accordion-toggle"
              *ngFor="let user of viewUsers"
            >
              <td>
                <button class="btn btn-default btn-xs">
                  <span class="glyphicon glyphicon-eye-open"></span>
                </button>
              </td>
              <td>{{ user.firstName }}</td>
              <td>{{ user.lastName }}</td>
            </tr>

            <tr>
              <td colspan="12" class="hiddenRow">
                <div class="accordian-body collapse" id="demo[[user.id]]">
                  <table class="table table-striped">
                    <thead>
                      <tr class="info">
                        <th>Job</th>
                        <th>Company</th>
                        <th>Salary</th>
                        <th>Date On</th>
                        <th>Date off</th>
                        <th>Action</th>
                      </tr>
                    </thead>
1

1 Answer 1

2
<tr data-toggle="collapse" data-target="#demo{{ user.id }}" class="accordion-toggle" *ngFor="let user of viewUsers"></tr>
Sign up to request clarification or add additional context in comments.

3 Comments

Good answers include some explanation—not just code
This HTML snippet utilizes Angular directives and interpolation to dynamically generate and style accordion toggle elements for each user in the viewUsers array.
Use the "edit" button to edit your answer to include that explanation instead of a comment.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.