Search code examples
javascripthtmlangularjsangularjs-ng-include

angular ng-include not working


The is a part of my html where I am trying to include the another HTML file "content.html" but it is not working. Those addresses in the source are correct but still I am not able to make it happen.

  <!DOCTYPE html>
  <html lang="en">
  <head>

   <!-- Basic Page Needs
  –––––––––––––––––––––––––––––––––––––––––––––––––– -->
  <meta charset="utf-8">
  <title>Your page title here :)</title>
  <meta name="description" content="">
  <meta name="author" content="">
 <!-- Scripts
 –––––––––––––––––––––––––––––––––––––––––––––––––– -->
 <script type="text/javascript" src="js\jquery-3.0.0.min.js"></script>
 <script type="text/javascript" src="js/angular.min.js"></script>
  </head>
  <body>
  <div ng-include src="'content.html'"></div>
  </body>
  </html>

and this is my content.html

  <div class="container">
  <h1>Heading!</h1>
  </div>

Solution

  • You should add ng-app="" to your page html tag, so that angular will get kick off on the page. After that will start traversing the page & will collect all directive & it will compile them.

    <html lang="en" ng-app="">
    

    Instead of ng-include with src you could directly pass template value in ng-include attribute as well.

    <div ng-include="'content.html'">
    

    Demo Plunkr