SoFunction
Updated on 2025-04-03

AngularJS basic ng-include directive simple example

AngularJS ng-include directive

AngularJS instance

Contains HTML files:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="/libs//1.4.6/"></script>
</head>
<body ng-app="">

<div ng-include="''"></div>

</body>
</html>

Running results:

File title

This text comes from the included file!

Definition and usage

ng-includeDirectives are used to contain external HTML files.

The content contained will be used as a child of the specified element.

The value of the ng-include property can be an expression that returns a file name.

By default, included files need to be included under the same domain name.

grammar

<element ng-include="filename" onload="expression" autoscroll="expression" ></element>

The ng-include directive is used as an element:

<ng-include src="filename" onload="expression" autoscroll="expression" ></ng-include>

All HTML elements support this directive.

Parameter value

value describe
filename File name, you can use expressions to return the file name.
onload Optional, an expression executed after the file is loaded.
autoscroll Optional, whether the included part can be scrollable on the specified view.

The above is a summary of the knowledge of AngularJS ng-include directives, and will be supplemented later.