AngularJS | ng-include Directive
AngularJS has a built-in directive to include the functionality from other AngularJS files by using the ng-include directive.The primary purpose of the “ng-include directive” is used to fetch, compile and include an external HTML file in the main AngularJS application.These are added as child nodes in the main application. The ng-include attribute’s value can also be an expression, that returns a filename. All HTML element supports this.
Syntax:
<element ng-include="filename" onload="expression" autoscroll="expression" > Content...</element>
Note: Here the onload and autoscroll parameter are optional , onload define an expression to evaluate when the included file is loaded and autoscroll define whether or not the included section should be able to scroll into a specific view.
-
Example:1
- External HTML file: Save this file as child.html.
<!-- child.html --><p>Hello Geeks from include component.</hp><!--I am a partial, i don't require head and body tags.-->chevron_rightfilter_none - Code:
<!DOCTYPE html><html><head><title>AngularJS | ng-include Directive</title><scriptsrc=</script></head><bodyng-app=""style="text-align: center"><h1style="color:green">GeeksforGeeks</h1><h3>ng-include Directive</h3><divng-include="'child.html'"></div></body></html>chevron_rightfilter_none - Output:

- Example 2:
- External HTML file: Save this file as table.html.
<!-- table.html --><table><trng-repeat="Subject in tutorials"><td>{{ Subject.Name }}</td><td>{{ Subject.Description }}</td></tr></table>chevron_rightfilter_none - Code:
<!DOCTYPE html><htmllang="en"><head><metacharset="UTF-8"><metaname="viewport"content="width=device-width, initial-scale=1.0"><metahttp-equiv="X-UA-Compatible"content="ie=edge"><title>AngularJS | ng-include Directive</title><scriptsrc=</script></head><bodyng-app="main-app"><center><h1style="color: green;">GeeksforGeeks</h1><h3>ng-include Directive</h3><divng-controller="AngularController"><divng-include="'table.html'"></div></div><script>var main_app = angular.module('main-app', []);main_app.controller('AngularController', function($scope) {$scope.tutorials =[{Name: "AngularJS", Description : "Front End Framework"},{Name: "NodeJS", Description : "Server side JavaScript"},{Name: "ExpressJS", Description : "Server side JS Framework"}];});</script></body></html>chevron_rightfilter_none - Output:

Recommended Posts:
- AngularJS | ng-app Directive
- AngularJS | ng-if Directive
- AngularJS | ng-jq Directive
- AngularJS | ng-src Directive
- AngularJS | ng-cut Directive
- AngularJS | ng-value Directive
- AngularJS | ng-csp Directive
- AngularJS | Directive
- AngularJS | ng-selected Directive
- AngularJS | ng-required Directive
- AngularJS | ng-paste Directive
- AngularJS | ng-srcset Directive
- AngularJS | ng-readonly Directive
- AngularJS | ng-blur Directive
- AngularJS | ng-bind Directive
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


