参见英文答案 >
*ngFor is not working in angular 21个
我开始使用Angular2(最终版本),我在使用* ngFor时遇到了一些问题.
我开始使用Angular2(最终版本),我在使用* ngFor时遇到了一些问题.
我已经构建了以下组件树:
主要 – >仪表板 – >警报
Unhandled Promise rejection: Template parse errors: Can’t bind to
‘ngForOf’ since it isn’t a kNown property of ‘div’.(“<div class=”item” [ERROR ->] *ngFor=”let alert of alerts”>
“): DashboarDalertsComponent@5:20 Property binding ngForOf not used by any directive on an embedded template.
Make sure that the property name is spelled correctly and all
directives are listed in the “directives” section.
它工作正常,但当我尝试在警报组件中添加* ngFor循环时,我收到以下错误:
DashboarDalertsComponent:
import {Component,OnInit} from "@angular/core"; import {Alert} from "../../shared/models/alert.model"; @Component({ selector: 'dashboard-alerts',templateUrl: './alerts.component.html' }) export class DashboarDalertsComponent implements OnInit { alerts:Alert[] = new Array<Alert>(); constructor() { this.alerts.push(new Alert('1','high','My alert1','12/11/2016 4:50 PM')); this.alerts.push(new Alert('2','low','My alert2','11/11/2016 9:50 PM')); this.alerts.push(new Alert('3','medium','My alert3','10/11/2016 2:50 PM')); } ngOnInit() { } }
alerts.component.html
<div class="item" *ngFor="let alert of alerts"> <span class="priority {{ alert }}"></span> <span class="title">{{ alert }}</span> <span class="time">3:40 PM</span> <a href="#" class="more-actions"><span>Actions</span></a> </div>
DashboardModule
@NgModule({ declarations: [ DashboarDalertsComponent ],providers: [],directives: [],}) export class DashboardModule { }
的AppModule
@NgModule({ imports: [ browserModule,DashboardModule ],declarations: [ AppComponent ],bootstrap: [AppComponent] }) export class AppModule { }
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。