ng-includeคำสั่งAngularJS


ตัวอย่าง

รวม HTML จากไฟล์ภายนอก:

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

ความหมายและการใช้งาน

คำng-includeสั่งรวมถึง HTML จากไฟล์ภายนอก

เนื้อหาที่รวมไว้จะถูกรวมเป็นโหนดย่อยขององค์ประกอบที่ระบุ

ค่าของng-includeแอตทริบิวต์ยังสามารถเป็นนิพจน์ โดยส่งคืนชื่อไฟล์

โดยค่าเริ่มต้น ไฟล์ที่รวมไว้จะต้องอยู่ในโดเมนเดียวกับเอกสาร


ไวยากรณ์

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

ng-include directive ยังสามารถใช้เป็นองค์ประกอบ:

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

รองรับโดยองค์ประกอบ HTML ทั้งหมด


ค่าพารามิเตอร์

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.