本文介绍了采用NG-控制器时,推迟装载模板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图推迟我的主控制器/模板(AppController的)加载,直到我加载用户服务配置文件。

I'm trying to defer loading of my main controller/template (AppController) until I load the users profile from a service.

对于所有的航行路线,我使用$ routeProvider与决心

For all navigation routes, I'm using $routeProvider with resolve

.when('/edit/:editId', {
    templateUrl: 'editTemplate.html',
    controller: 'EditController' // this is a child controller of AppController
    resolve: {
         currentUser: ['svc.user', function(userSvc) { return userService.getUser(); }]
    }
// and so on..

但AppController的我使用

But for AppController I'm using

我怎样才能做一个AppController的决心?从本质上讲,我想一个userService.getUser()返回一个承诺完成AppController的实际运行之前执行的,我不知道如何做到这一点使用NG-INIT尽管(或者,如果有可能,我还以为只有前pressions不承诺可以执行)。

How can I do a resolve for AppController? Essentially, I'd like a userService.getUser() which returns a promise to finish executing before AppController is actually run, I'm not sure how to do this using ng-init though (or if it's possible, i thought only expressions not promises could be executed).

感谢您的帮助/帮助。

推荐答案

在本视频中看到:

您应该尝试:

.when('/edit/:editId', {
  templateUrl: 'editTemplate.html',
  controller: 'EditController' // this is a child controller of AppController
  resolve: {
     currentUser: ['svc.user', function(userSvc) { return userService.getUser(); }]
     app: function ($q) {
                var defer = $q.defer();
                defer.resolve();
                return defer.promise;
     }
}

这篇关于采用NG-控制器时,推迟装载模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-23 17:59