Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exception: Can't bind to 'ngFor' since it isn't a known native property

What am I doing wrong?

import {bootstrap, Component} from 'angular2/angular2'  @Component({   selector: 'conf-talks',   template: `<div *ngFor="talk of talks">      {{talk.title}} by {{talk.speaker}}      <p>{{talk.description}}    </div>` }) class ConfTalks {   talks = [ {title: 't1', speaker: 'Brian', description: 'talk 1'},             {title: 't2', speaker: 'Julie', description: 'talk 2'}]; } @Component({   selector: 'my-app',   directives: [ConfTalks],   template: '<conf-talks></conf-talks>' }) class App {} bootstrap(App, []) 

The error is

EXCEPTION: Template parse errors: Can't bind to 'ngFor' since it isn't a known native property ("<div [ERROR ->]*ngFor="talk of talks"> 
like image 996
Mark Rajcok Avatar asked Dec 01 '15 03:12

Mark Rajcok


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 Ng Forof since it isn't a known property of DIV?

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.

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

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.

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

I missed let in front of talk:

<div *ngFor="let talk of talks"> 

Note that as of beta.17 usage of #... to declare local variables inside of structural directives like NgFor is deprecated. Use let instead.

<div *ngFor="#talk of talks"> now becomes <div *ngFor="let talk of talks">

Original answer:

I missed # in front of talk:

<div *ngFor="#talk of talks"> 

It is so easy to forget that #. I wish the Angular exception error message would instead say:
you forgot that # again.

like image 94
Mark Rajcok Avatar answered Sep 18 '22 13:09

Mark Rajcok