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

时间:2015-09-25 07:47:08

标签: angularjs directive

我添加了angularjs指令,但它在应用启动时没有运行。 调试控制台中没有打印调试。

html代码:

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

angularjs指令:

    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);
            //}
        }
    };
});

0 个答案:

没有答案