指令的HTML:
<div my-directive input-config=scopeObj1 current-pricing=scopeObj2 needs-refresh=scopeFlag1 > </div>
我的指令设置如下:
App.directive('myDirective',['', function(){
return {
restrict:'AE',
scope:{
inputConfig:'=',
needsRefresh: '=',
currentPricing: '='
},
transclude: true,
templateUrl: '...html',
link:function(scope,element,attrs){
console.log(scope);
if(scope.needsRefresh) {
scope.currentPricing = data;
scope.needsRefresh = false;
console.log(scope);
} else {
}
}
};
}]);
console.log都显示相同的值,我有以下错误
不可分配的模型表达式:true(指令:myDirective)
如果我在sencond console.log之前放置一个断点,我可以看到值已更新,但在打印之前它们正在重置。
任何想法/建议都表示赞赏。
答案 0 :(得分:0)
改变你在隔离范围内获取输入的方式
scope:{
inputConfig:'@',
needsRefresh: '@',
currentPricing: '@'
},
因为您发送的是常量值而不是2路绑定变量。
使用=
在范围内传递值时,指令期望值为变量而不是常量。你现在对指令说的是读取$ scope.true,其中你实际意图是按原样读取常量。因此使用=
。
您可以详细了解他的here