2017-03-04 18 views
1

我使用角UI路由器0.2.15並有一個頁面/profile文件現在想編輯按鈕和鏈接的點擊輪廓變得/型材/編輯父模板也顯示在子狀態。如何擺脫這個問題?

現在我named views和UI路由器的嵌套視圖概念之間有點困惑,並與他們兩個嘗試,但問題仍然存在。

  1. 使用嵌套狀態

    .state("profile", { 
          url: '/profile', 
          controller: 'UserController', 
          controllerAs: 'vm', 
          templateUrl: 'app/views/user/profile.html', 
          data: { 
           requiresAuth: true, 
           pageTitle: 'Profile' 
          } 
         }) 
         .state("edit", { 
          url: '/edit', 
          parent:'profile', 
          templateUrl: 'app/views/user/edit_profile.html', 
          data: { 
           requiresAuth: true, 
           pageTitle: 'Edit Profile' 
          } 
         }) 
    

profile.html

<div ui-view=""></div> 
<button type="button" class="btn fa fa-pencil" ui-sref="edit"></button> 

在這種情況下,我的問題是,當我編輯網頁上點擊,它也也顯示父視圖的內容。如何處理這個?

回答

1

子狀態將被放置在父母的佔位符的位置

<div ui-view=""></div> 

這不會隱瞞父視圖,只需更換該div與孩子的模板

但我們真的可以取代孩子的父視圖一。問題的關鍵是目標的index.html(根)ui-view

.state("edit", { 
    url: '/edit', 
    parent:'profile', 
    views: { 
     '@': { 
      templateUrl: 'app/views/user/edit_profile.html', 
     }, 
    }, 
    data: { 
     requiresAuth: true, 
     pageTitle: 'Edit Profile' 
    } 
}) 

認爲'@'說的神奇的名字 - 它是根和無名。還有很多類似的Q &答:Angular UI Router - Nested States with multiple layouts