【发布时间】:2015-10-28 19:41:30
【问题描述】:
我需要在所有页面上重用boostrapnavbar,所以我一直在尝试为菜单创建一个文件并使用ng-includeangularJS标签呈现它
菜单就是这个文件/partials/top_menu.html
<div class="container">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="index.html">EXAMPLE</a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav navbar-right">
<li>
<a href="about.html">Quienes Somos</a>
</li>
<li>
<a href="organizacion.html">Organización</a>
</li>
<li>
<a href="servicios.html">Servicios</a>
</li>
<li>
<a href="clientes.html">Clientes</a>
</li>
<li>
<a href="portfolio-3-col.html">Galeria</a>
</li>
</ul>
</div>
<!-- /.navbar-collapse -->
</div>
这里是 index.html,它试图包含该部分作为页面的导航菜单
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content="">
<title>TITLE</title>
<!-- Bootstrap Core CSS -->
<link href="css/bootstrap.min.css" rel="stylesheet">
<!-- Custom CSS -->
<link href="css/modern-business.css" rel="stylesheet">
<!-- Custom Fonts -->
<link href="font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css">
<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
<script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script>
</head>
<body>
<!-- Navigation -->
<nav class="navbar navbar-default navbar-fixed-top topnav" role="navigation">
<div ng-include="'partials/top_menu.html'"></div>
</nav>
<body>
问题是菜单栏根本没有被渲染,WebDeveloper 控制台没有显示任何错误或文件丢失
我做错了什么,或者如果这是错误的方法,请告诉我我可以实现它
【问题讨论】:
-
您也可以将你也可以自定义指令来实现它,但最好使用 ng include@Tomislav 您可能已经看到我的 index.html 指向其他需要包含该菜单的 html 文件。好吧,我认为您想使用部分和路由来开发 SPA(单页应用程序)。如果不是,那么您的方法是可以的。您的 index.html 中也缺少 ng-app 指令。试试
标签: css angularjs twitter-bootstrap