gpt4 book ai didi

Angular2(最终版)*ngFor 在组件 : Can't bind to 'ngForOf' since it isn't a known property of 'div'

转载 作者:太空狗 更新时间:2023-10-29 17:23:18 27 4
gpt4 key购买 nike

<分区>

我开始使用 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>

仪表板模块

@NgModule({
declarations: [
DashboardAlertsComponent
],
providers: [],
directives: [],
})
export class DashboardModule {
}

应用模块

@NgModule({
imports: [
BrowserModule,
DashboardModule
],
declarations: [
AppComponent
],
bootstrap: [AppComponent]
})
export class AppModule {
}

P.S 我阅读了很多关于这个问题的建议解决方案,但没有一个解决这个问题

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com