angular ng-include not working
Asked Answered
L

1

5

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>
Lot answered 20/7, 2016 at 19:30 Comment(0)
U
7

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

Unclog answered 20/7, 2016 at 19:34 Comment(2)
Don't you also need to use it as ng-include="'content.html'" when using it as an attribute? Isn't src only valid when using ng-include as an element?Mccurry
@Mccurry Thanks for heads up, will add it in answer as an improvement , Thanks :)Unclog

© 2022 - 2024 — McMap. All rights reserved.