我是AngularJS的新手。有人可以帮助您找到这是什么问题。在此示例中双重绑定不起作用。
http://jsfiddle.net/gm2hg/120/
<body ng-app="animateApp">
<br/> the watch is triggered only on the load of the page, not on subsequent changes to the property "acts"
<div ng-controller="tst">
<input type="button" bn="" acts="acts" value="Add Action" /> {{acts.crop}}
</div>
</body>
var animateAppModule = angular.module('animateApp', [])
animateAppModule.controller('tst', function($scope) {
$scope.acts = {
crop: "test"
};
$scope.$watchCollection('model.acts', function(newValue, oldValue) {
alert("as");
})
})
animateAppModule.directive('bn', function() {
return {
restrict: "A",
scope: {
acts: '='
},
link: function($scope, iElement, iAttrs) {
alert("l");
iElement.click(function() {
alert($scope.acts.crop);
$scope.acts = {
crop: "real"
};
alert($scope.acts.crop);
})
}
}
})
首先,您必须以这样的方式编写手表功能:
$scope.$watch('acts', function(newValue, oldValue) {
alert("as");
});
现在,您已设置了从指令更改范围之后的应用:
$scope.$apply();
检查更新的JSFIDDLE:http://jsfiddle.net/gm2hg/121/
希望这对您有帮助。谢谢。