我在外部组件模板中使用ngFor循环,通过单向绑定和@Input decorator显示内部组件的多个值。
注:出于隐私原因,我正在使用命名替代品。
外部模板:
<h1>Things</h1>
<ul>
<li *ngFor="let obj of objects">
<app-inner-component [object]="obj"></app-inner-component>
</li>
</ul>
外部TS代码
export class DashboardComponent implements OnInit {
object = [
new Object('firstObject'),
new Object('secondObject')
];
...
对象模型
export class Object {
private name: string;
constructor(name: string) {
this.name = name;
}
}
<h2>{{this.name}}</h2>
内部组件TS代码
export class InnerComponent implements OnInit {
@Input() object: Object;
渲染的外部模板仅显示一个项目符号(不显示名称)。当我注释掉HTML选择器时,
app-inner-component
,存在两个项目符号。
我希望外部模板是:
东西
-第一个对象
-第二个对象