使用Angular js嵌入Html页面

时间:2016-07-08 10:57:23

标签: javascript jquery html angularjs twitter-bootstrap

我是Angular js的新手,我试图在bootstrap模板的帮助下使用Angular js在html页面中嵌入html片段。

这是我的index.html

<body >
  <div ng-app="">
     <div ng-include="mainmenu.html"></div>


       <!-- Page Content -->
          <div class="container">

         <div class="row">
            <div class="col-lg-12 text-center">
               <h1>Starter Template</h1>
                <p class="lead">Complete with pre-defined file paths that you won't have to change!</p>

           </div>
         </div>
    <!-- /.row -->

    </div>
<!-- /.container -->
 </div>
  <!-- jQuery Version 1.11.1 -->
  <script src="js/jquery.js"></script>

  <!-- Bootstrap Core JavaScript -->
  <script src="js/bootstrap.min.js"></script>
  <script  src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
</body>

这是我的manimenu.html

<!-- Navigation -->
<nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
    <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="#">Start Bootstrap</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">
                <li>
                    <a href="#">About</a>
                </li>
                <li>
                    <a href="#">Services</a>
                </li>
                <li>
                    <a href="#">Contact</a>
                </li>
            </ul>
        </div>
        <!-- /.navbar-collapse -->
    </div>
    <!-- /.container -->
</nav>

index.html和mainmenu.html都在同一个文件夹中。但是mainmenu.html没有在index.html中显示。如果有人知道请帮我解决这个问题

2 个答案:

答案 0 :(得分:5)

您所缺少的是对模板引用的引用。没有引号,它被评估为表达式。

<div ng-include="'mainmenu.html'"></div>

来自documentation

评估为URL的角度表达式。如果源是字符串常量,请确保将其包装在单引号中,例如SRC = “ 'myPartialTemplate.html'”。

答案 1 :(得分:4)

。使用此功能或结帐以下链接

<div ng-include src="'mainmenu.html'"></div>

http://stackoverflow.com/questions/13943471/angularjs-ng-include