【发布时间】:2018-11-25 03:20:50
【问题描述】:
我有一个子组件
parent.component.html
<child-component (changeVal) = "parentObj"></child-component>
parent.component.ts
parentObj = {
someDate = new Date()
}
// function changing the parentObj
callOnClick() {
this.parentObj.someDate = new Date('20 June 2018');
}
子组件.ts
@Input('changeVal')
ngOnChanges() {
// console i never see
console.log('parentObj Changed and got me here');
}
为什么在这种情况下 onChanges 钩子没有运行?我正在更改 callOnClick 方法中的输入值,当 changeVal 的值更改时它不应该触发吗?
【问题讨论】:
-
感谢拉维的简单解决方案。荣誉!
标签: angular