angularjs:如何访问指令(文本)值
angularjs: howto access directive (text) value
我想编写一个指令,根据我作为参数(字符串值)提供的角色来显示/隐藏元素。
我有以下指令:
(function() {
'use strict';
angular
.module('fuse')
.directive('showWhenRole', showWhenRoleDirective);
/** @ngInject */
function showWhenRoleDirective(auth) {
return {
restrict: 'A',
scope: {
showWhenRole: '@'
},
compile: function(scope, tElement) {
console.log("showWhenRoleDirective",scope.showWhenRole);
// if (auth.isAdmin()) {
// tElement.show();
// } else {
// tElement.hide();
// }
}
};
}
})();
我的HTML元素如下所示:
<md-menu-bar id="user-menu" show-when-role="admin">
当我查看控制台时,信息是:
showWhenRoleDirective undefined
我做错了什么?
从compile
移动到link
,scope
在compile
阶段中不可用
相关文章:
- mouseover和mouseleave文本颜色更改在指令链接中不起作用
- Angular指令中的最佳实践是将文本输入设置为英尺和英寸的格式
- HTML 标记在使用 Angular 指令时被视为纯文本
- 输入文本的ng重复没有填充指令中的ng模型
- 在编译AngularJS指令中的模板之前,先评估传入的文本
- 在$invalid上添加验证指令并从文本框中删除数据的指令
- 基于嵌套指令Angular的宽度更改文本
- 设置要显示的文本格式的指令
- AngularJS - 指令填充文本框,但ng-model没有值
- ng-bind 用作文本区域的指令,但不是输入标签
- maxlength在ckeditor angularjs指令的文本区域中不起作用
- AngularJS数字文本输入:指令与函数
- 如何在 angular.js 指令中使用调用元素的文本
- angularjs:如何访问指令(文本)值
- 如何在指令的情况下更改下拉列表的默认文本,并对指令应用所需的验证
- 指令没有't更改文本区域模型后发生火灾
- 如何防止ng模型覆盖指令生成的输入文本的值
- 为什么在编译包含指令的html文本(从db)时出现无限摘要错误
- angularjs指令来操作文本值
- 用于替换文本的 Angularjs 指令