2016-10-22 130 views
0

以角度使用ui-router,我設置了'用戶'狀態,我的應用程序中的所有用戶都以ng-repeat的形式返回。我想不過子狀態的視圖繼承父視圖「模板/用戶/ index.html的」(這是我的app.js來爲用戶創建個人資料頁面顯示狀態:UI-Router嵌套狀態視圖不呈現(呈現父視圖)

.state('users', { 
    abstract: true, 
    name: 'users', 
    url: '/users', 
    views: { 
     nav: { 
     templateUrl: 'templates/navbar.html', 
     controller: 'MainCtrl' 
     }, 
     content: { 
     templateUrl: 'templates/users/index.html', 
     controller: 'UsersCtrl' 
     } 
    } 
    }) 
    .state('users.show', { 
     url: '/show/:id', 
     views: { 
     nav: { 
      templateUrl: 'templates/navbar.html', 
      controller: 'MainCtrl' 
     }, 
     content: { 
      templateUrl: 'templates/users/show.html', 
      controller: 'UsersCtrl' 
     } 
     } 
    }); 

這裏是我的index.html:

<div class="container"> 
    <label>Search: <input ng-model="searchText"></label> 
    <a ui-sref="users.show({id: user.id})" ng-click="showUser(user.id)" ng-repeat="user in users | filter:searchText "> 
    <h2> {{ user.name }} </h2> 
    <h3> {{ user.email }} </h3> 
    <button ng-click="createConversation({sender_id: current_user.id, recipient_id: user.id})" >Message</button> 
    </a> 
</div> 

在瀏覽器的URL是http://localhost:8080/#/users/show/2然而HTML文件被繼承的users.show狀態是父母的用戶(index.html的)文件

任何幫助表示讚賞!

+0

請閱讀此[嵌套路線](http://stackoverflow.com/questions/34251255/creating-nested-route-app-in-angular-using-angular-ui-router-and-switching-betwe/ 34251256#34251256) – Maher

回答

1

嵌套視圖​​實際上將在user視圖內呈現。因此,您只需要在templates/users/index.html之內放置另一個<ui-view>,其中show視圖將呈現。