我使用的是Angular2 2.1.0。当我想要显示公司列表时,我得到了这个错误。

在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>

当前回答

如果您有模块实现,则必须导入组件并在声明中设置组件

祝你编程好运:)

其他回答

将该组件添加到app.module中

import { ModalComponent } from './modal/modal.component';

@NgModule({
  declarations: [ModalComponent],
  entryComponents: [ModalComponent],
  
  }),
  providers: [
  ],
  bootstrap: [AppComponent]
})

我有一个问题,因为json数据中的空白。

就我而言, 我已经在我的共享模块和组件将要使用的功能模块中包含了CommonModule,但在我的情况下,我在服务器启动(编译)时保存了一些文件,也许这就是为什么它没有正确地获取所包含模块的注册表

我重启了我的本地服务器,它解决了我的问题

在我的例子中,这个组件没有在app.module.ts中列出。

自定义模块需要通用模块

import { CommonModule } from "@angular/common";


@NgModule({
  imports: [
    CommonModule
  ]
})