2017-12-03 217 views
1

繼承解析的依賴這裏是我的代碼子狀態不是從父狀態

$stateProvider 
     .state('admin', { 
      abstract: true, 
      templateUrl: "views/common/content.html", 
      resolve: { 
       channel: function($stateParams){ 
        return $stateParams.id 
       } 
      } 
     }) 
     .state('admin.dash',{ 
      url: "/dash", 
      templateUrl: "views/admin/admin_dash.html" 
     }) 

和我有使用NG-控制器此admin_dash.html鑑於許多控制器。並且在這些控制器(子)中的任何一箇中,我都無法注入「通道」,這是應該繼承的父狀態已解決的依賴關係。

+0

ui-router的最新版本,注入意味着'注入'父狀態已解決的依賴關係到綁定到子狀態的控制器,在這種情況下'通道' –

回答

1

解決方案injectables將不可用於任何舊的ng-controller,但僅限於指定給該狀態的控制器。

E.g.

$stateProvider 
    .state('admin', { 
     abstract: true, 
     templateUrl: "views/common/content.html", 
     resolve: { 
      channel: function($stateParams){ 
       return $stateParams.id 
      } 
     } 
    }) 
    .state('admin.dash',{ 
     url: "/dash", 
     templateUrl: "views/admin/admin_dash.html", 
     // Injectable here 
     controller: function(channel, $rootScope) { 
      console.log('Received channel from parent resolve:', channel); 
      // If need for ng-controller bound controllers... 
      $rootScope.channel = channel; 
     } 
    })