在Angular上使用路由配置服务

时间:2016-01-20 23:45:34

标签: javascript angularjs ionic-framework angular-ui-router angular-routing

如果我没有开始,我必须限制对州的访问。

我有:

App - > InitService(工厂)

// ...
var started = false;

var start = function () {
    asyncStart()
       .then(function () {
           started = true;
       });
};

var isStarted = function () {
    return started;
};

return {
    start: start,
    isStarted: isStarted
};

//...

App - >运行

//...
    $stateProvider

        .state('welcome',
            url: '/welcome',
            controller: 'WelcomeCtr',
            template: welcomeTemplate
         })

         .state('app', {
            url: '/app',
            abstract: true,
            controller: 'AppCtr',
            template: appTemplate,
            resolve: {
                security: [
                     '$q',
                     'InitService',
                      function ($q, InitService) {
                          if (!InitService.isStarted()) {
                              return $q.reject(new Error("Is not started"));
                          }
                      }
                ]
            }
         })

    ;
//...

当我运行应用程序时,出现此错误:

Uncaught Error: [$injector:modulerr] Failed to instantiate module App due to:
Error: [$injector:modulerr] Failed to instantiate module App due to:
Error: [$injector:unpr] Unknown provider: InitService

我认为这是因为module.run在服务工厂定义之前运行。如果是这样,我应该如何在 module.run 加载后注入服务?

有更正确的方法吗?

对不起,我的可怜的好事。

0 个答案:

没有答案