0
我有一个指令,我只是渲染,如果我的身份验证服务这样告诉我:Angularjs指令条件呈现不NG-如果
<div my-loggedin-directive ng-if="security.isAuthenticated()"></div>
该指令本身是很空:
.directive('myLoggedinDirective', [
function() {
return {
templateUrl: 'modules/myLoggedinDirective.tpl.html',
restrict: 'A',
replace: true,
link: function($scope) {
$scope.$on('$destroy', function() {
console.log('$destroy');
});
}
};
}
]);
由于我指令应该始终在我登录时呈现,ngIf逻辑应该在指令声明内,而不是在ng-if(没有ngIf的指令将被完全破坏)。
如何知道我想要的行为与ngIf
相同?请问如何更改指令代码(在指令声明内的安全服务中注入测试)? :
- 存在于DOM指令,只有当
nfIf
解析为true
- 的$自动呼叫破坏时
nfIf
决心false
)?
我试图用compile
功能和观察者观看security.isAuthenticated()
没有成功
感谢它帮我;)我也注入服务作为一个依赖摆脱额外的属性。 –