Can't bind to 'ngForOf' since it isn't a known property of 'tr' (final release)

167

I'm using Angular2 Final release (2.1.0). When I want to display a list of companies, I got this error.

in file.component.ts :

public companies: any[] = [
    { "id": 0, "name": "Available" },
    { "id": 1, "name": "Ready" },
    { "id": 2, "name": "Started" }
];

in file.component.html :

<tbody>
  <tr *ngFor="let item of companies; let i =index">
     <td>{{i}}</td>
     <td>{{item.name}}</td>
  </tr>
</tbody>

This question is tagged with angular angular2-template

~ Asked on 2016-10-30 17:12:43

The Best Answer is


278

Add BrowserModule to imports: [] in @NgModule() if it's the root module (AppModule), otherwise the CommonModule.

// older Angular versions
// import {BrowserModule, CommonModule} from '@angular/common';

import { BrowserModule } from '@angular/platform-browser'
..
..
@NgModule({
  imports: [BrowserModule, /* or CommonModule */],
  ..
})

~ Answered on 2016-10-30 17:14:51


54

In my case, the issue was that my teammate mentioned *ngfor in templates instead of *ngFor. Strange that there is no correct error to handle this issue (In Angular 4).

~ Answered on 2017-12-22 18:10:37


Most Viewed Questions: