0
嘿每個人我打電話指令和傳遞硬編碼的指令,但它沒有通過。我不能在我的代碼中遇到什麼問題。 代碼:指令屬性值不通過
我打電話指令是這樣的:
<div ng-controller="EmployeeController">
<off-balance user-key="18" collapse-hide="true"></off-balance>
</div>
指令代碼:
App.directive('offBalance', ['OffService', 'toaster', OffBalance]);
function OffBalance(OffService, toaster,) {
var directive = {
link: link,
restrict: 'E',
templateUrl: 'app/modules/sometemplate.html',
scope: {
userKey: '=',
collapsehide: '=?',
},
scope: true
}
}
return directive;
function link(scope, element, attr) {
scope.$watch('userKey', function (newVal) {
alert("userKey" + newVal);
});
scope.$watch('collapsehide', function (newVal) {
alert("collapsehide" + newVal);
});
}
}
用戶鑰和collapsehide都是不確定的。請大家幫我解決了這個問題
有沒有什麼辦法,我們可以同時使用範圍? –
不,你不能。兩個範圍都有其自己的含義。當我們編寫'scope:true'指令時會得到新的作用域,當我們編寫'scope:{}'時,指令會獲得新的隔離作用域。 – varit05