AngularJS ng-include Directive

Updated on     Kisan Patel

Use ng-include, you can fetch, compile, and include an external HTML fragment into your current application.

For example, your main HTML file can have different sections like a header, a footer, a sidebar etc. You can put the template for these components in separate HTML files, and include them into your main HTML.

The following is an example code for the usage of the ngInclude directive:

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

<h1>This is the studentView1</h1>


<h1>This is the studentView2</h1>


<!DOCTYPE html>
<html xmlns="">
      <title>AngularJS ng-include Example</title>
      <script src=""></script>
  <div ng-app="myApp" ng-controller="studentController">
      <div ng-include="'template/studentView1.html'"></div>
      <div ng-include="'template/studentView2.html'"/></div>

<script type="text/javascript">
  var myModule = angular.module("myApp", []);

  myModule.controller('studentController', function ($scope) {


You can also use ng-include as a standalone element as follow:

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


Leave a Reply