Local variable within a ngFor

0

I have an input text inside an ngFor and I would like to define a dynamic local variable that would have a unique id value for each input, so I can perform the .focus () of this input, but I do not know how to do this , I have tried in many ways and I did not succeed.

I would like to set the idEmail of each email as my local variable To be able to access it with my @ViewChild

<tr *ngFor="let email of Emails">
    <td *ngIf="!isUpdating(email.idEmail)">
        {{ email.enderecoEmail }}
    </td>
    <td *ngIf="isUpdating(email.idEmail)">
        <input [(ngModel)]="txtEmail" #email.idEmail type="text" class="form-control">
    </td>
</tr>

Please help me I'm stuck on this task 2 days and I do not find the solution

    
asked by anonymous 12.11.2018 / 15:24

1 answer

0

Hello, Welcome to SOpt.

Good to solve your problem we can use attr in input to set the id of it.

Ex.

<input attr.id="input_email_{{email.idEmail}}">

Then just capture it and execute whatever you want.

Ex.

let thatemail = document.getElementById('input_email_2');

thatemail.focus();

Full example at: link

    
12.11.2018 / 16:10