3

I'm filling a table with data from an array and I want to focus a custom input on the last element of the table, so I have this:

<tr *ngFor="let detail of detailsList; let i = index" (dblclick)="showDetailDetails(detail.ID, i)"> <th>{{ a few table fields}}</th> <th> <md-input-container> <input [focus]="detailsList.length-1 == i" mdInput type="number" (keypress)="qtKeyDown($event)" (change)="getTotalNetAmount(i)" [(ngModel)]="detail.OrderedQuantity" [ngModelOptions]="{standalone: true}" value="{{detail.OrderedQuantity}}" min="1" OnlyNumber="true" [disabled]="!editMode"> </md-input-container> </th> <th> (More fields) </th> </tr> 

It works as intended but when there is more than 1 item in the array I'm getting an error in my console. I notice that the problem is in this code:

detailsList.length-1 == i 

Is there anyway to fix this error? The Code is working as intended so this error don't bother the behavior the website, the problem is that I don't want the user to see errors in the browser console.

1 Answer 1

10

This is usually related to changeDetection. Without seeing your code, I am guessing you are doing a push() at some point. Add this after your push():

import { ChangeDetectorRef } from '@angular/core'; constructor(private ref: ChangeDetectorRef) { } this.something.push(someVar); this.ref.detectChanges(); 
Sign up to request clarification or add additional context in comments.

6 Comments

Thank you for the help. I'm not at work now, so I will try it on monday and then give you the feedback.
Note that this is a dev error. Once the code is built for production, users will not see this error, so if you can't solve it, you won't have to worry about users seeing it. The error is related to change detection though.
So, since it's working as intended I shouldn't worry about it? It's good to know that users will not see it. Thank you!
Ya pretty much. I mean and error is an error and you should try to fix it, but it's only an error you'll see in dev builds.
I would say worry about it! read this to understand why blog.angularindepth.com/…
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.