2017-10-07 47 views
0

有人可以幫助我在角度js中嵌套視圖。 我用這個點符號帶點符號的嵌套視圖

$stateProvider 
    .state('contacts/:id', { 
    templateUrl: 'contacts.html', 
    controller: function($scope){ 
    $scope.contacts = [{ name: 'Alice' },  { name: 'Bob' }]; 
    } 
    }) 
    .state('contacts/:id.list/:id', { 
    templateUrl: 'contacts.list.html' 
    }); 

    function MainCtrl($state){ 
    $state.transitionTo('contacts/:id.list/:id'  ); 
    } 

在HTML我打電話的狀態變化也是這樣

<a ui-sref="contacts/{{value.id}}.list/{{value.id}}">get<\a> 

但我總是得到

angular.js:12477 Error: Could not resolve 'contact/2.list/2' from state 'contact/:id'

日Thnx

編輯:


我做了一個像@Maxim Shoustin的改變回答。現在狀態改變,但在孩子導航當我點擊項目,父UI的觀點是完全刷新(小孩導航和用戶界面視圖)不僅孩子
現在我的狀態看起來像這樣

.state('client', { 
       url: '/client/info/:itemID', 
       templateUrl: 'clientInfo.html', 
       controller: 'detailControllerClient as vm', 
      }) 
      .state('client.detail', { 
       url: '/detail/:itemID', 
       templateUrl: 'itemInfoById.html', 
       controller: 'detailControllerClient as vm', 
      }) 

和HTML是這裏。 (infoDisplay.html裏面的index.html父視圖。此UI視圖代碼波紋管子視圖(client.detail)) infoDisplay.html

<div class="new_nav col-lg-1 col-md-1 col-sm-2 col-xs-12"> 
      <table class="table-hover"> 
       <thead> 
        <tr> 
         <th>item ID</th> 
        </tr> 
       </thead> 
       <tbody> 
        <tr ng-repeat="(key, value) in clientDetail"> 
         <td><a ui-sref=".detail({'itemID': value.id})">{{value.id}}</a></td>  
        </tr> 
       </tbody> 
      </table> 
     </div> 
     <div ui-view></div> 

回答

1

<a ui-sref="contacts/{{value.id}}.list/{{value.id}}">get<\a>

你不能id因爲角度使用id.list確定模式中的重複名稱id。但id_list還行。例如

ui-sref文檔

其中狀態是:

.state('contacts', { 
    url: '/contacts/:id_list/:id', 
    templateUrl: 'contacts.html' 
    }) 

和HTML:

<a ui-sref="contacts({'id_list': value.id, 'id': value.id})" >contacts</a> 

Demo Plunker

+0

對不起......這是錯誤的...它的UI -sref不是用戶狀態...這裏是URL中的例子https://github.com/angular-ui/ui-rout er/wiki/Nested-States - & - Nested-Views vut對我來說這不起作用... – Arter

+0

@Arter很好,它不是你寫的。 :)在你的情況''id.list'是參數,但不是狀態 –

+0

它有意義:) ...您的答案之前是解決方案或我需要改變別的東西?星期一,當我回來工作時,我會嘗試這個......我會以結果迴應你。 thnx男子爲此 – Arter