angular - 组件数据在多个实例之间共享
问题描述
考虑以下组件:
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
! 正常吗?
解决方案
那是导致该行为的引导模式。
推荐阅读
- android - 如何重置计步器?
- python - 是否可以使用 python 在 sqlite3 中运行多个语句?
- javascript - '无法设置未定义的属性“innerHTML”' - 但它已定义
- vim - 根据模式匹配突出显示整行
- graph - GTFS 到图形的转换?
- sql-server - 如何让 SSIS 包动态选择所需的连接管理器?
- java - 是否可以使用通配符逻辑“*”通过 Apache Maven 目标和选项列出特定目录?
- visual-studio-code - VSCode 在打开某些文件时隐藏文件夹内容
- arrays - 读取文件文本的奇数行并添加到 bash 中的数组
- javascript - 如何在编码中从字符串中删除文本