无法绑定到"ngForOf",因为它不是"tr"的已知属性(最终发行版) [英] Can't bind to 'ngForOf' since it isn't a known property of 'tr' (final release)

查看:58
本文介绍了无法绑定到"ngForOf",因为它不是"tr"的已知属性(最终发行版)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Angular2 Final版本(2.1.0).当我想显示公司列表时,出现此错误.

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

file.component.ts中:

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>

推荐答案

如果BrowserModule是根模块(AppModule),则将BrowserModule添加到@NgModule()中的imports: [],否则是CommonModule.

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

这篇关于无法绑定到"ngForOf",因为它不是"tr"的已知属性(最终发行版)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆