Angularjs angular指令在应用程序启动期间未运行

Angularjs angular指令在应用程序启动期间未运行,angularjs,directive,Angularjs,Directive,我添加了angularjs指令,但它在应用程序启动期间不运行。 调试控制台中不打印调试 html代码: <li has-role="ROLE_ADMIN" class="dropdown pointer"></li> 您是否使用angular.module('myApp',[])定义了属性模块?这里显示的代码只是一个引用,但您需要添加一个数组来初始化它。是的,它在主文件中正确初始化。它工作正常,可能您没有将JS文件包含在指令中。我已经检查了includes,将我的

我添加了angularjs指令,但它在应用程序启动期间不运行。 调试控制台中不打印调试

html代码:

   <li has-role="ROLE_ADMIN" class="dropdown pointer"></li>

您是否使用
angular.module('myApp',[])
定义了属性模块?这里显示的代码只是一个引用,但您需要添加一个数组来初始化它。是的,它在主文件中正确初始化。它工作正常,可能您没有将JS文件包含在指令中。我已经检查了includes,将我的指令分配给我的angular directive模块,它工作正常(我使用的是typescipt,当文件包含在参考文件中时,可能是顺序问题)。谢谢帮助:)
    angular.module('myApp').directive('hasRole', function (){
    return {
        restrict: 'A',
        link: function (scope, element, attrs) {
            var setVisible = function () {
                    console.log('hasAnyRole, setVisible');
                    element.removeClass('hidden');
                },
                setHidden = function () {
                    console.log('hasAnyRole, setHidden');
                    element.addClass('hidden');
                },
                defineVisibility = function (reset) {
                    console.log('hasAnyRole, defineVisibility');
                    // other logic here...
                    setVisible();            
                },
                role = attrs.hasRole.replace(/\s+/g, '');

            //if (roles.length > 0) {
                defineVisibility(true);
            //}
        }
    };
});