如何创建一个boostrap导航栏并在每个页面上重复使用

时间:2015-08-05 20:48:02

标签: css angularjs twitter-bootstrap

我需要在所有网页上重复使用boostrap navbar,因此我尝试为菜单创建一个文件并使用ng-include angularJS标记进行渲染/ p>

菜单是此文件/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&oacute;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控制台没有显示任何错误或文件缺失

我做错了什么或者如果这是错误的做法让我知道我能实现吗

2 个答案:

答案 0 :(得分:1)

您需要将ng-app添加到index.html的正文标记

<body ng-app>

这是AngularJS bootstraping指令。如果没有这个,AngularJS进程就无法启动。

您需要为任何需要使用angularJS指令

的html文件执行此操作

答案 1 :(得分:-1)

使用此脚本可能对您有所帮助:

require 'nokogiri'
require 'open-uri'

testarray = ["test"]

url = "http://namegeneratorbay.com/username-generator"
document = Nokogiri::HTML(open(url))
username = document.at_css('h2').text.strip

testarray.push(username)

puts testarray
#=> ["test", "Rhirawyr"]

必须包含Jquery文件。