Angular 在模板中使用ngFor和@Input decorator显示同一组件的多个

Angular 在模板中使用ngFor和@Input decorator显示同一组件的多个,angular,Angular,我在外部组件模板中使用ngFor循环,通过单向绑定和@Input decorator显示内部组件的倍数 注意:出于隐私原因,我使用命名替代品 外部模板: <h1>Things</h1> <ul> <li *ngFor="let obj of objects"> <app-inner-component [object]="obj"></app-inner-component> </li> <

我在外部组件模板中使用ngFor循环,通过单向绑定和@Input decorator显示内部组件的倍数

注意:出于隐私原因,我使用命名替代品

外部模板:

<h1>Things</h1>
<ul>
  <li *ngFor="let obj of objects">
    <app-inner-component [object]="obj"></app-inner-component>
  </li>
</ul>
对象模型

export class Object {
   private name: string;

   constructor(name: string) {
      this.name = name;
   }
}
内部组件模板

export class DashboardComponent implements OnInit {
  object = [
     new Object('firstObject'),
     new Object('secondObject')
  ];
...
<h2>{{this.name}}</h2>
export class InnerComponent implements OnInit {
  @Input() object: Object;
渲染的外部模板仅显示一个bulletpoints(无名称显示)。当我注释掉HTML选择器,
app-internal-component
时,出现了两个BulletPoint

我希望外部模板为:

事情

-firstObject


-secondObject

我能看到的第一件事是模板
{{this.name}}
中的
this
的存在,它不应该存在于模板中


你的模板应该是
{{object.name}

我能看到的第一件事是
this
在模板
{{this.name}}
中的存在,它不应该存在于模板中


你的模板应该是
{{object.name}

哇,它工作了。非常感谢。
this
是否不是引用组件实例的有效关键字?是的,如果变量是
public
,则不需要使用单词
this
,因为它只存在于
ts/js
文件中,因此它起作用了。非常感谢。
this
是否不是引用组件实例的有效关键字?是的,如果变量是
public
,则不需要单词
this
,因为它仅存在于
ts/js
文件中