1

I have a simple table:

...
   <tr>
      <td>
        <a href="#">Add select</a>
      </td>
       <td>
        <a href="#">Add select</a>
      </td>
       <td>
        <a href="#">Add select</a>
      </td>
    </tr>
     <tr>
      <td>
        <a href="#">Add select</a>
      </td>
       <td>
        <a href="#">Add select</a>
      </td>
       <td>
        <a href="#">Add select</a>
      </td>
    </tr>

When user clicks on Add Select link I want to create select tag. For dropdown list I use ng2-select So, I have two problems, how to get specific td when user clicks Add select and how to create select component in that td.

1 Answer 1

1
<tr>
  <td>
    <a href="#" (click)="addSelect(0)">Add select</a>
    <ng2-select *ngFor="let item in ng2Selects[0]"></ng2-select>
  </td>
   <td>
     <a href="#" (click)="addSelect(1)">Add select</a>
     <ng2-select *ngFor="let item in ng2Selects[1]"></ng2-select>
  </td>
   <td>
ng2Selects = [];
addSelect(index:number) {
  if(this.ng2Selects.length < index) {
    this.ng2Selects[index] = [];
  }
  this.ng2Selects[index].push('dummy');
}
Sign up to request clarification or add additional context in comments.

4 Comments

There are can be a lot of select inside one cell.
Thanks for the answer. But, I think your didn't get question. I want to create ng2-select itself and add to cell, not options for select.
Where do you see options in my answer? Did you even try it?
Oh, didn't get your code at a glance. I will try it asap. Thanks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.