组件数据在多个实例之间共享

问题描述 投票:0回答:1

考虑以下组件:

  export class PropertyViewComponent implements OnInit {
  @Input() property: any;
  constructor() {}

  ngOnInit() {
  }

  onAddClick() {
    console.log(this.property);
  }
}

和以下模板:

<button type="button" class="btn btn-primary" (click)="onAddClick()">َAdd</button>

父组件模板是:

<app-property-view *ngFor="let p of properties" [property]="p"></app-property-view>

当我运行该应用程序时,它将打印property中的第一个properties!正常吗?

angular ngfor
1个回答
0
投票

这是导致此行为的引导程序模式。

© www.soinside.com 2019 - 2024. All rights reserved.