通过指令分配新值的最佳方式是什么?双向数据绑定。更改指令中的范围值
我在这里有一个小提琴,我试过。 http://jsfiddle.net/user1572526/grLfD/2/。但它并不奏效。
我的指令:
myApp.directive('highlighter', function() {
return {
restrict: 'A',
replace: true,
scope: {
activeInput: '='
},
link: function (scope, element, attrs) {
element.bind('click', function() {
scope.activeInput = attrs.setInput
})
}
}
});
而且我的控制器:
function MyCtrl($scope) {
$scope.active = {
value : true
};
}
而我的观点:
<h1 highlighter active-input="active.value" set-input="false">Click me to update Value in scope: {{active}}</h1>
所以我要做的就是更新与给定的scope.active属性setInput。
任何想法我在做什么错在这里?
[Using scope。$ watch and scope。$ apply](http://stackoverflow.com/questions/15112584/using-scope-watch-and-scope-apply) – Stewie