6

I have a table where inputis placed:

<tr *ngFor="let persons of ReceivedData">
  <td *ngFor="let person of persons">

    <div *ngIf="person.personId === editRowId && person.editable === true ">
        <input type="number" [(ngModel)]="person.CarCount" 
               (focusout)="focusOutFunction()"/>
    </div>                            
    <div *ngIf="person.editable === false " (click)="toggle(person)">
        {{ person.CarCount ? person.CarCount : '-' }}
    </div>

  </td>
<tr>

But the focusout event isn't fired. Here's the method handling the focusout function:

focusOutFunction() {        
}

Interestingly focusout works perfectly when input is not placed inside table:

<input type="number" (focusout)="focusOutFunction()" />

How can I fire an event when I focus inside of the table?

Rohan Fating
  • 2,135
  • 15
  • 24
StepUp
  • 36,391
  • 15
  • 88
  • 148

2 Answers2

5

Here's a working plnkr of focusout proc'ing inside a table with a similar setup as you have. The other key is to include an autofocus attribute:

 <input type="number" [(ngModel)]="person.CarCount" 
           (focusout)="focusOutFunction()" autofocus/>
Z. Bagley
  • 8,942
  • 1
  • 40
  • 52
3

Use blur event to get focus out.

<input type="number" [(ngModel)]="person.CarCount" 
               (blur)="focusOutFunction()"/>
Rohan Fating
  • 2,135
  • 15
  • 24