简体   繁体   中英

Angular js not working resolve

Have State Route:

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

This is my service:

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

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

Controller:

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

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

When I call, nothing happens State Profile. But if I change my resolve to:

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

Then everything works. Why does not it work?

I found the problem. That's the way to work:

resolve:
 {
    AuthService: AuthService
 }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM