使用带有异步数据的ngNewRouter初始化Angular 1.4应用程序

时间:2015-05-21 08:54:08

标签: angularjs asynchronous angularjs-new-router

我在这里知道这个问题:AngularJS : Initialize service with asynchronous data我过去曾在1.1和1.2中使用过。

但这需要您使用旧的ngRoute模块。我正在使用ngNewRouter(可用于角度1.x)并且没有路由提供者的解析方法。

但是可以在组件中完成,而不是使用主控制器:

//before navigation finishes, useful to load required data
appController.prototype.activate = function() {
  console.log ('loading data for the user');
  console.log (this.authService.requestCurrentUser());
  return this.authService.requestCurrentUser();
}

但是,主控制器不是组件,因此 $ componentLoaderProvider 不可用。

如何让应用程序等待异步数据,而不添加将this.authService.requestCurrentUser()返回到每个组件?

谢谢!

0 个答案:

没有答案