Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular 2 RC5: Can't bind to 'ngFor' since it isn't a known property of

Tags:

angular

After upgrading to RC5, I suddenly got this error:

Can't bind to 'ngFor' since it isn't a known property of 'div'. ("

<div [ERROR ->]*ngFor="t of test">{{t}}</div>")

The HTML:

<div *ngFor="t of test">asdas</div>

All posts on this topic explain that you need to import BrowserModule, but I already did that.

like image 903
Boland Avatar asked Aug 22 '16 20:08

Boland


People also ask

Can't bind to ngFor since it isn't a known property?

ngFor is not a known property would mean for whatever reason, ngFor cannot be recognized in the application. However, the real problem was that ngFor was recognised but the syntax of ngFor was wrong. Anyway, let's hope Angular team improves their logging in future updates.

Can't bind to ngIf since it isn't a known property?

Solution for Angular Can't bind to 'ngIf' since it isn't a known property of 'div' There are multiple ways to fix this. Incorrect ngIf syntax One way, This is due to an error caused due to misspelling capital 'I' for div. To solve this, Import CommonModule or BroswerModule or both into app.

Can't bind to '* ngForOf since it isn't a known property of TR?

Error: NG0303: Can't bind to 'ngForOf' since it isn't a known property of 'ion-item'. Explanation: This error occurs when you use ngIf/ ngFor in the component, where you have not imported CommonModule. Fix: To fix this you have to import the CommonModule in the module file which is used by that HTML file.

How do you use ngFor?

To Use ngFor directive, you have to create a block of HTML elements, which can display a single item of the items collection. After that you can use the ngFor directive to tell angular to repeat that block of HTML elements for each item in the list.


1 Answers

After banging my head against the wall, I found the solution: I had forgotten the word "let" in front of my variable!

Pre RC5 this used to work, so this is a breaking change in RC5. I know let is required, but previously this just worked. And the error is not helpful at all.

Hope this helps!

like image 76
Boland Avatar answered Oct 05 '22 11:10

Boland