2015-12-30 63 views
0

我可以在AngularJS中擁有頁面的一些常量部分,例如徽標,側邊菜單,麪包屑?我可以在AngularJS中擁有一些不變的頁面嗎?

問題是如何讓任何部分不變並僅導航內容部分?

是唯一的方法是包含html片段?

+0

使用角度路段 – 1Mayur

+0

你的意思是這個http://angular-route-segment.com/ ? – Dims

+0

查看下面的答案。它具有來自該網站的代碼 – 1Mayur

回答

1

<html> 
 

 
<head> 
 
</head> 
 

 
<body ng-app=""> 
 
    <div> 
 
    <p>CONSTANT PART</p> 
 
    </div> 
 
    <div ui-view> 
 
    content use ui router for changing content configure routes in app.js 
 
    </div> 
 
</body> 
 
</html

使用ui-路由器根據所述狀態

https://github.com/angular-ui/ui-router

+0

UI-Router使用其自己的「狀態」概念在其上實現其自己的URL路由機制。角度路由段不會嘗試替換AngularJS中的某些內容。它基於內置的$ route引擎,因此它試圖擴展它而不是替換。 – 1Mayur

0

Angular Route Segment

bower install angular-route-segment 

該庫提供UI視圖的內容改變兩段代碼:$ routeSegment服務和app-view-segment指令。兩者都放在他們自己的模塊,你必須包括爲您的應用程序模塊的依賴關係:

var app = angular.module('app', ['ngRoute', 'route-segment', 'view-segment']); 

$routeSegmentProvider.segment('s1', { 
    templateUrl: 'templates/section1.html', 
    controller: MainCtrl}); 

$routeSegmentProvider.within('s1').segment('home', { 
    templateUrl: 'templates/section1/home.html'}); 

$routeSegmentProvider.within('s1').segment('itemInfo', { 
    templateUrl: 'templates/section1/item.html', 
    controller: Section1ItemCtrl, 
    dependencies: ['id']}); 

$routeSegmentProvider.within('s1').within('itemInfo').segment('overview', { 
    templateUrl: 'templates/section1/item/overview.html'}); 

然後,任何應用程序視圖段標籤(這類似於內置NG-視圖)在DOM會填充相應的路線段項目。您必須提供段索引作爲此指令的參數,以使其知道應鏈接到樹中的哪個段級別。

的index.html:

<ul> 
    <li ng-class="{active: $routeSegment.startsWith('s1')}"> 
     <a href="/section1">Section 1</a> 
    </li> 
    <li ng-class="{active: $routeSegment.startsWith('s2')}"> 
     <a href="/section2">Section 2</a> 
    </li> 
</ul> 
<div id="contents" app-view-segment="0"></div> 

哪裏UL代碼是靜態的,將在每個頁面上顯示

相關問題