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

半兽人 发表于: 2019-06-11   最后更新时间: 2019-06-11 10:19:45   4,514 游览

版本: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
发表于 2019-06-11

在根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],
  ..
})
你的答案

查看AngularJS相关的其他问题或提一个您自己的问题