ng-includeChỉ thị AngularJS


Thí dụ

Bao gồm HTML từ một tệp bên ngoài:

<div ng-include="'myFile.htm'"></div>

Định nghĩa và Cách sử dụng

Chỉ ng-includethị bao gồm HTML từ một tệp bên ngoài.

Nội dung được bao gồm sẽ được bao gồm dưới dạng các biểu tượng con của phần tử được chỉ định.

Giá trị của ng-includethuộc tính cũng có thể là một biểu thức, trả về một tên tệp.

Theo mặc định, tệp được bao gồm phải nằm trên cùng một miền với tài liệu.


Cú pháp

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

Chỉ thị ng-include cũng có thể được sử dụng như một phần tử:

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

Được hỗ trợ bởi tất cả các phần tử HTML.


Giá trị tham số

Value Description
filename A filename, written with apostrophes, or an expression which returns a filename.
onload Optional. An expression to evaluate when the included file is loaded.
autoscroll Optional. Whether or not the included section should be able to scroll into a specific view.