问题描述
如何在除登陆页面之外的每个页面上显示导航栏,以便不必在每个需要的页面上附加导航栏文件?现在我已经在主应用程序布局中包含了导航栏,应该如何处理它以使其保持干燥?
演示(每个页面都有导航栏):
var App = angular.module('app', ['ui.router']);App.config(function($stateProvider, $urlRouterProvider) {$stateProvider.state('家', {网址:'/家',模板网址:'home.html'}).state('关于', {网址:'/关于',templateUrl: 'about.html'}).state('登陆页面', {url: '/登陆页面',templateUrl: '登陆页面.html'});$urlRouterProvider.otherwise('/home');});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script><script src="//cdnjs.cloudflare.com/ajax/libs/angular-ui-router/0.2.8/angular-ui-router.min.js"></script><link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css" rel="stylesheet" type="text/css"/><div ng-app="app"><div ng-include="'navbar.html'"></div><div class="容器"><div ui-view></div>
<script type="text/ng-template" id="navbar.html"><nav class="navbar navbar-inverse" role="navigation"><div class="navbar-header"><a class="navbar-brand" ui-sref="landingpage">LandingPage</a>
<ul class="nav navbar-nav"><li><a ui-sref="home">Home</a></li><li><a ui-sref="about">关于</a></li><li ng-hide="signedIn()"><a href="/login">登录</a></li><li ng-show="signedIn()"><a ng-click="logout()">注销</a></li></nav><script type="text/ng-template" id="home.html"><h1>温馨页面</h1><script type="text/ng-template" id="about.html"><h1>关于页面</h1><script type="text/ng-template" id="landingpage.html"><h1>着陆页</h1><a ui-sref="home">家</a>