在指令中,我无法进入authService中的`getUser`方法

时间:2018-07-15 16:31:27

标签: angularjs

在指令中,我无法进入authService中的getUser方法:

    angular.module('app').directive('guard', [ function ( authService) {

        return {
            restrict: 'A',
            link: function (scope, element, attrs) {

           //     element.hide();

                function currentUserHasAnyPermission(requiredP) {
                    return authService.getUser().then(function (currentUser) {
                       var currentUserP = currentUser.permissions;
                        return _.intersection(currentUserP, requiredP).length > 0;
                    });
                }
            }
        };

    }]);

返回错误:

Cannot read property 'getUser' of undefined
   at currentUserHasAnyPermission

1 个答案:

答案 0 :(得分:1)

删除方括号:

map

有关更多信息,请参见AngularJS Developer Guide - Implicit Dependency Injection

相关问题