无法检查用户配置文件服务cll的角度

时间:2016-04-16 19:45:30

标签: angularjs angular-ui-router

我正在尝试检查用户个人资料,然后授权或不授权以访问某个页面。 我正在定义这项服务

.factory(
            'accountService',
            function($resource, $http, sessionService, $state) {
                var service = {};
                service.getProfile = function() {
                    $http.get("/myapp/rest/account/getuserprofile").success(function(data) {
                        userProfile = data.userProfile;
                        if (userProfile == "1"){
                            service.isStudent = false;
                            console.log("1", service.isStudent);
                        }
                        else
                            service.isStudent = false;
                        console.log("2", service.isStudent);
                    }).error(function() {
                    });
                    return service.isStudent;
                }                   
                return service;
            })

然后我正在检查此服务

$scope.$on('$stateChangeStart', function(event, toState,
                        toParams, fromState, fromParams) {
                    $scope.uiRouterState = $state;
                    if ((toState.data.authenticate
                            &&accountService.getUser())) {
                        $state.go("login");
                        event.preventDefault();
                    }
                    if ((toState.data.teacher &&accountService.isStudent ===1)) {
                        $state.go("home");
                        event.preventDefault();
                    }
                });

但问题是accountService.isStudent始终未定义。 我怎么检查呢?

0 个答案:

没有答案