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

Mourad Idrissi picture Mourad Idrissi · Oct 30, 2016 · Viewed 137.4k times · Source

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>

Answer

G&#252;nter Z&#246;chbauer picture Günter Zöchbauer · Oct 30, 2016

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 */],
  ..
})