2016-07-08 122 views
5

我是Angular js的新手,我正嘗試使用Angular js將html片段嵌入html頁面並藉助bootstrap模板。使用Angular js嵌入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中顯示。如果有誰知道,請幫我解決這個

+0

創建一個plunker – Sajeetharan

回答

4

。嘗試用這種或者檢出低於

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

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

謝謝薩E .. :) – Raj

+0

你歡迎親愛的隊友:) - –

5

鏈接所有你缺少的是周圍的參考模板的報價。沒有引號,它被評估爲一個表達式。

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

documentation

角表達式計算到URL。如果源是一個字符串常量,請確保將其用單引號括起來,例如SRC = 「 'myPartialTemplate.html'」。