I want to watch for changes in a dictionary, but for some reason watch callback is not called.
(我想要查看字典中的更改,但由于某种原因,不会调用监视回调。)
Here is a controller that I use:
(这是我使用的控制器:)
function MyController($scope) {
$scope.form = {
name: 'my name',
surname: 'surname'
}
$scope.$watch('form', function(newVal, oldVal){
console.log('changed');
});
}
Here is fiddle .
(这是小提琴 。)
I expect $watch callback to be fired each time name or surname is changed, but it doesn't happen.
(我希望每次更改名称或姓氏时都会触发$ watch回调,但不会发生。)
What is the correct way to do it?
(这样做的正确方法是什么?)
ask by Vladimir Sidorenko translate from so
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…