我有一个显示计数器的小应用程序,其中包含事件和实际日期之间的天数。我是为了学习Angular而创建的。
我有一个计数器列表,以后可以在列表中看到每个计数器的视图。我想删除一个计数器,但是对于该任务,我需要将一个对象赋予自定义角度组件。但是,当我尝试检索其组件时,它是未定义的。Angular只能给出基本类型吗?
我的柜台模特:
export class Counter {
picture: string;
synopsis: string;
constructor(public title: string, public date: Date) {
}
}
我用该代码致电柜台清单:
<div *ngFor="let counter of counters">
<app-display-test title="{{ counter.title }}"
date="{{ counter.date }}"
counter="{{counter}}">
</app-display-test>
</div>
我的显示模型:
export class DisplayTestComponent implements OnInit {
@Input() title: string;
@Input() date: Date;
@Input() counter: Counter;
constructor() {
}
ngOnInit() {
console.log(this.title);
this.calculateCUrrentDate(); // my method for calculate the time
console.log(this.counter);
console.log(this.date);
}
}
在ngOnInit方法中,标题和日期具有值,但是计数器输入未定义,我不明白为什么
尝试这样:
TS:
counters = []
constructor() {
this.counters.push(new Counter("test",new Date))
}
模板:
<div *ngFor="let counter of counters">
<app-display-test [title]="counter.title" [date]="counter.date" [counter]="counter">
</app-display-test>
</div>
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句