我有一個指令需要與使用隔離範圍的指令一起工作。這當然引起了這個錯誤:在沒有隔離範圍的指令中雙向數據綁定
Multiple directives asking for new/isolated scope
我的代碼看起來大致是這樣的:
HTML:
<p custom_directive='variable' vendor_directive>Test</p>
JS:
app.directive('ExampleDirective',function() {
return {
restrict: 'A',
scope: {
exampleDirective: '='
},
link: function(scope,element,attributes){
// manipulate scope.exampleDirective
}
}
});
我已經嘗試刪除範圍完全從我的指示和沿用以下內容:
scope.exampleDirective = scope.$eval(attributes.exampleDirective)
但是,這隻能看到對象的工作,而我的目標是其他類型的變量。
這是如何實現的?
使用[$ parse service](https://docs.angularjs.org/api/ng/service/$parse)創建setter和getter函數。 – georgeawg