2016-10-11 23 views
0

問題#1角嵌套的路線不正確加載

我想自定義自己的角路由提供商的例子。 我試圖爲第1部分中的每個元素實現單獨分隔的選項卡。

我的部分#/ section1/hs(hs.html)仍然實現#/ section1/hs/X而不是#/ section1/hs/ov爲標籤。

您可以看到app.js代碼here

我試過使用prefs example &其他方法,但它不起作用。

問題2:

而且當我在templateUrl使用另一個角度應用程序路徑,頁面似乎並不正確加載(只顯示文本)。 是因爲我們無法在templateUrl中調用另一個Angular應用程序。我不確定這是因爲我不是AngularJS的專家。

以下是我的代碼this example.Any幫助將不勝感激。

section1.html

<li ng-repeat="i in items" 
ng-class="{active:('s1.itemInfo' | routeSegmentStartsWith) && 
('id' | routeSegmentParams) == i}"> 

<a ng-href="#{{'s1.itemInfo' | routeSegmentUrl: {id: i} }}">{{i}}</a> 

</li> 

<li ng-class="{active:('s1.hs' | routeSegmentStartsWith)}"> 
<a ng-href="#{{'s1.hs' | routeSegmentUrl }}">HTML/CSS</a> 
</li> 

<li ng-class="{active:('s1.prefs' | routeSegmentStartsWith)}"> 
<a ng-href="#{{'s1.prefs' | routeSegmentUrl }}">Preferences</a> 
</li> 

hs.html

<ul class="nav nav-tabs"> 
<li ng-class="{active: $routeSegment.contains('ov')}"> 
<a href="#/section1/hs/ov">Overview</a> 
</li> 
</ul> 

<div app-view-segment="2" class="anim" No tab selected.> </div> 
+0

爲什麼不使用ui路由器,它會更好地在你的情況下 –

回答

0

如果你身在/section1/hs/ov鍵入它會引導您到正確的網頁?您的誤解是,導航到s1.hs的標籤應該來自templates/secion1/hs.html,但它被覆蓋。

因此,直到您導航到較高的存在的目錄(在此例中爲section1/hs/ov),模板將不會加載。 /section1/anything/tab1將導致仍然加載tab1.html,因爲除了設置標題名稱外,其他標識實際上並未用於此目的。

要使用templateUrl轉到不同的角度應用程序,即不在應用程序模塊聲明中作爲依賴項注入的應用程序,您需要執行頁面重新加載。如果您將templateUrl設置爲/templates/newapp.html並在您的html ng-href={{'newapp' | routeSegmentUrl }}" m中確保忽略#,它應該可以工作。