2016-10-11 40 views
1

我試圖使用angular-ui-router來定義我的應用程序來定義一個有兩個狀態的網站:main和checkout。主要狀態應該有多個「節」標籤,我試圖定義爲UI視圖項目。我不知道我的路由設置有什麼問題,但是我感覺main.html沒有被加載。對什麼是錯我的定義任何建議...我能避免使用意見的secions,只需使用NG-包括...兩個狀態與定義一個視圖的意見

routes.js

app.config(function($stateProvider, $urlRouterProvider) { 
    $urlRouterProvider.otherwise('/main'); 
    $stateProvider 
     .state('main', { 
      url: '/main', 
      controller: 'MainCtrl', 
      templateUrl: 'templates/main.html', 
      views:{ 
       'home': { 
        templateUrl: 'templates/main.home.html' 
       }, 
       'about': { 
        templateUrl: 'templates/main.about.html' 
       }, 
       'services': { 
        templateUrl: 'templates/main.services.html' 
       }, 
       'shop': { 
        templateUrl: 'templates/main.shop.html', 
        controller: 'ShopCtrl' 
       } 
      } 
     }) 
     .state('checkout', { 
      url: '/checkout', 
      templateUrl: 'templates/checkout.html', 
      controller: 'CheckoutCtrl' 
}); 

的index.html

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

模板/ main.html中

<section ui-view="home" id="home"></section> 
<section ui-view="about" id="about"></section> 
<section ui-view="services" id="services"></section> 
<section ui-view="shop" id="shop"></section> 

基本上頁面加載,但主要或結賬狀態不加載。我如何將事物嵌套錯誤?

回答

0

通過不指定父項,可以將兩個狀態都映射到index.html中的默認UI視圖。所以當訪問主狀態時,不會有任何模板鏈接到默認的ui-view,這是唯一存在於現有html中的模板。

所以主要國家應該有這樣的定義:

.state('main', { 
      url: '/main', 
      views:{ 
       '': { 
        controller: 'MainCtrl', 
        templateUrl: 'templates/main.html', 
       }, 
       '[email protected]': { 
        templateUrl: 'templates/main.home.html' 
       }, 
       '[email protected]': { 
        templateUrl: 'templates/main.about.html' 
       }, 
       '[email protected]': { 
        templateUrl: 'templates/main.services.html' 
       }, 
       '[email protected]': { 
        templateUrl: 'templates/main.shop.html', 
        controller: 'ShopCtrl' 
       } 
      } 
     }) 
+0

感謝您的答覆。這似乎只呈現在主頁上的第一個視圖「主頁」,而不是所有的主頁 – rex

+0

這裏是證明這是解決方案的猛擊者https://plnkr.co/edit/N1RzdjsebV7Zz9fTGopQ?p=preview – rave

相關問題