我不明白为什么当我更改输入中的绑定原语时 $onChanges 没有启动。有人可以看到我做错了什么,并以简单的方式解释这一点吗?在我无法让它在我的实际应用程序中工作之后,我做了一个快速测试应用程序的plunkr 。
angular
.module('test', [])
.component('test', {
template: '<child application="vm.application"></child>',
controller: 'testCtrl as vm'
})
.controller('testCtrl', function() {
var vm = this;
vm.$onInit = function () {
vm.application = {
data: {
name: 'Test'
}
}
};
})
.component('child', {
template: '<input type="text" ng-model="vm.application.data.name">',
bindings: {
application: '<'
},
controller: 'childCtrl as vm'
})
.controller('childCtrl', function() {
var vm = this;
vm.$onChanges = function (changes) {
console.log('CHANGED: ', changes);
};
})