首页 > 解决方案 > 组件数据在多个实例之间共享

问题描述

考虑以下组件:

  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! 正常吗?

标签: angularngfor

解决方案


那是导致该行为的引导模式。


推荐阅读