2016-12-21 9 views
2

同じコントローラを使用するために複数のビューを取得しようとしています。私はこれまでにいくつかのことを試みましたが、どれもうまくいかないようです。 "doesntの仕事" と私は、コントローラMapControllerありえないが、インスタンス化を意味し、ビュー、コントローラ、これはすべきexistingquestionsを見たUIルータ複数のビューが同じコントローラを共有しています

$stateProvider.state(PageStateNames.COMPONENTS_LIVEMAP, { 
    url: "/components/vehicles/:vehicle/:panel", 
    views: { 
     "": { 
      controller: "MapController as vm" 
     }, 
     "[email protected]": { 
      templateUrl: "....html" 
     }, 
     "[email protected]": { 
      templateUrl: "....html" 
     } 
    } 
}); 

$stateProvider.state(PageStateNames.COMPONENTS_LIVEMAP, { 
    url: "/components/vehicles/:vehicle/:panel", 
    controller: "MapController as vm" 
    views: { 
     "[email protected]": { 
      templateUrl: "....html" 
     }, 
     "[email protected]": { 
      templateUrl: "....html" 
     } 
    } 
}); 

を見ることができません作業。私は何かを逃したか?

答えて

0
$stateProvider.state(PageStateNames.COMPONENTS_LIVEMAP, { 
    url: "/components/vehicles/:vehicle/:panel", 
    views: { 
     "": { 
      templateUrl: "......html", 
      controller: "MapController as vm" 
     }, 
     "[email protected]": { 
      templateUrl: "....html", 
      controller: "MapController as vm" 
     }, 
     "[email protected]": { 
      templateUrl: "....html", 
      controller: "MapController as vm" 
     } 
    } 
}); 
+0

コントローラを3回作成しませんか?理想的にはトップレベルの状態のために1つだけ持っています – Chris

+0

親ビューコントローラのデータは、コントローラに言及せずにアクセスできます –

0

同じコントローラを状態で使用するには、子 - 親入れ子状態を使用できます。例:

$stateProvider.state('home', { 
    templateUrl: '....html', 
    controller: 'ParentController' 
}) 

.state('home.livemap', { // << this state will use parent controller instance, this is the dot notation to make livemap a child state of home (more info here https://github.com/angular-ui/ui-router/wiki/Nested-States-and-Nested-Views 
templateUrl: '....html' 
}); 
関連する問題