2016-05-26 2 views
0

に、コントローラからデータを渡すために、これは私のファイルで指定されたルートです:どのようtemplateUrl

.state(
    "path", { 
    url: "/{path:.*}", 
    views: { 
     "secondnav": { 
     templateUrl: "/App/View/Partials/_partDetails.html", 
     controller: 'unitDetailsController' }, 
     "body": { 
      controller: 'unitDetailsController', 
      templateUrl: function($scope) { 
      return "/app/View/unitDetails.html"; 
      } 
     } 
     } 
    }) 

templateUrlにコントローラunitDetailsControllerからデータを渡すためにどのように?

+0

コントローラーの$ scopeで再生されるデータは、テンプレートで自動的に使用できるようにする必要があります。それはあなたが求めていることですか、私は疑問を誤解していますか? –

答えて

0

あなたは、次のコードのようにデータを渡すことができます:

UI-ルータの設定:

angular 
    .module('angularApp', [ 
    'ngAnimate', 
    'ngCookies', 
    'ngResource', 
    'ngRoute', 
    'ngSanitize', 
    'ngTouch', 
    'ui.router' 
    ]) 
    .config(function($stateProvider, $urlRouterProvider) { 
    // 
    // For any unmatched url, redirect to /state1 
    $urlRouterProvider.otherwise("/state1"); 
    // 
    // Now set up the states 
    $stateProvider 
     .state('state1', { 
     url: "/state1/:id", 
     templateUrl: "views/partials/state1.html", 
     }); 
    }); 

テンプレート:

<div ng-controller="RowsCtrl"> 
    <h1>State 1</h1> 
    <p>Id: {{id}}</p> 
    <div ui-view></div> 
</div> 
関連する問題