我有这个:
// child component
this.$onChanges = () => {
console.log(this.test);
}
// parent component
$scope.test = {
team: "barcelona"
};
// parent component html
<my-component test="test"></my-component>
// parent component
$timeout(() => {
$scope.test.team = "Real madrid"; // NOT fire the $onChanges!
$scope.test = {
team: "Real madrid";
} // DOES fire the $onChanges!
}, 2000);
如您所见,仅在分配值时才触发组件$ onChanges函数,而不仅仅是更新。
该怎么办?