版本:Angular Final release(2.1.0)
当我想通过下列代码展示列表时,报错了:
public companies: any[] = [
{ "id": 0, "name": "Available" },
{ "id": 1, "name": "Ready" },
{ "id": 2, "name": "Started" }
];
file.component.html :
<tbody>
<tr *ngFor="let item of companies; let i =index">
<td>{{i}}</td>
<td>{{item.name}}</td>
</tr>
</tbody>
报错:
Can't bind to 'ngForOf' since it isn't a known property of 'tr' (final release)
Ask
在根module(AppModule)中的@NgModule()中添加BrowserModule引入:
import {BrowserModule} from '@angular/platform-browser'; @NgModule({ imports: [BrowserModule, /* or CommonModule */], .. })
其他的module引入CommonModule.
import {CommonModule} from '@angular/common'; @NgModule({ imports: [CommonModule], .. })
你的答案