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