Angular js无法解决问题

时间:2016-04-23 13:54:36

标签: javascript angularjs routing

有州路线:

.state('stateProfile', {
        url: '/Profile',
        views: {
            "ContentContainer": {
                templateUrl: '/Navigation/Profile',
                controller: AuthController,
                resolve: {
                    message:  function (AuthService) {
                        return AuthService.GetMessage();
                    }
                }
            }

这是我的服务:

var AuthService = function ($timeout, $q, $location) {
return{

    GetMessage : function () {
        return "Hello";
        }
} 
};
AuthService.$inject = ['$timeout', '$q', '$location'];

控制器:

var AuthController = function (message, $q, $location, $timeout) {
console.log('auth work');
console.log(message);
};

AuthController.$inject = ['message', '$q', '$location', '$timeout'];

当我打电话时,State Profile没有任何反应。但如果我改变决心:

resolve:
{
        message:  function (AuthService) {
        return "Test resolve";
}

然后一切正常。为什么不起作用?

1 个答案:

答案 0 :(得分:0)

我发现了问题。这是工作方式:

resolve:
 {
    AuthService: AuthService
 }