2017-02-21 104 views
0

我有以下的代码,但我仍然试图去掌握Angular UI Router。我有一个父母状态,所以我可以使用resolve调用一个函数,并将其应用于其所有孩子。我的问题是,这个代码create-prealert.html没有出现,EnterDataController没有发射。Angular UI路由器不加载子模板UIr

正在发生的事情是,两个警报发生,然后没有更多。

我可以确认一切都很好,一旦我删除父母状态或如果我删除parent : app,

背后是如何工作,我失踪的基础?

我觉得没有其他代码的需要,因为每个事情都是完美的,当不试图与父母国家的任何事情。

编辑:我也可以确认它与resolve无论在哪种状态。我尝试了没有他们,仍然是同样的问题。

$stateProvider 
      .state('app', { 
       controller: 'MainController as data', 
       resolve: { 
        checkAuth: ['Auth','$timeout',function(Auth, $timeout){ 
         return $timeout(function(){ 
           alert('This is the alert for the parent state'); 
          } 
          , 500 
         ); 
        }] 
       } 
      }) 
      .state('prealert', { 
       parent : 'app', 
       url: '/create-prealert', 
       templateUrl: 'views/create-prealert.html', 
       controller: 'EnterDataController as data', 
       resolve: { 
        checkAuth: ['Auth','$timeout',function(Auth, $timeout){ 
         return $timeout(function(){ 
           alert('This is the alert for the child state'); 
          } 
          , 500 ...loading... 
         ); 
        }] 
       } 

      }) 
      .state('received', { 
       url: '/received', 
       templateUrl: 'views/received.html', 
       controller: 'EnterDataController as data' 
      }); 
    }); 

回答

0

我解决了这个问题,至少在某种程度上我明白了一些事情。

我试图放入其他模板来查看会发生什么,并且一旦它加载了模板,就意识到一切都很好。

然后我创建了一个parent.html文件,其中包含<div ui-view></div>,它工作。我忍不住想我接近这一切都是错误的。但无论如何它为我工作。

 .state('app', { 
      templateUrl: 'views/parent.html', 
      controller: 'MainController as data', 
      resolve: { 
       checkAuth: ['Auth','$timeout',function(Auth, $timeout){ 
        return $timeout(function(){ 
          alert('This is the alert for the parent state'); 
         } 
         , 500 
        ); 
       }] 
      } 
     }) 
相关问题