Fetches, compiles and includes an external HTML fragment.
By default, the template URL is restricted to the same domain and protocol as the application document. This is done by calling $sce.getTrustedResourceUrl on it. To load templates from other domains or protocols you may either whitelist them or wrap them as trusted values. Refer to Angular's Strict Contextual Escaping.
In addition, the browser's Same Origin Policy and Cross-Origin Resource Sharing (CORS) policy may further restrict whether the template is successfully loaded. For example, ngInclude
won't work for cross-domain requests on all browsers and for file://
access on some browsers.
<ng-include src="string" [onload="string"] [autoscroll="string"]> ... </ng-include>
<ANY ng-include="string" [onload="string"] [autoscroll="string"]> ... </ANY>
<ANY class="ng-include: string; [onload: string;] [autoscroll: string;]"> ... </ANY>
Animation | Occurs |
---|---|
enter | when the expression changes, on the new include |
leave | when the expression changes, on the old include |
The enter and leave animation occur concurrently.
Click here to learn more about the steps involved in the animation.Param | Type | Details |
---|---|---|
ngInclude | src | string | angular expression evaluating to URL. If the source is a string constant, make sure you wrap it in single quotes, e.g. |
onload (optional) | string | Expression to evaluate when a new partial is loaded. Note: When using onload on SVG elements in IE11, the browser will try to call a function with the name on the window element, which will usually throw a "function is undefined" error. To fix this, you can instead use data-onload or a different form that matches onload . |
autoscroll (optional) | string | Whether - If the attribute is not set, disable scrolling. - If the attribute is set without value, enable scrolling. - Otherwise enable scrolling only if the expression evaluates to truthy value. |
Emitted every time the ngInclude content is requested.
Param | Type | Details |
---|---|---|
angularEvent | Object | Synthetic event object. |
src | String | URL of content to load. |
Emitted every time the ngInclude content is reloaded.
Param | Type | Details |
---|---|---|
angularEvent | Object | Synthetic event object. |
src | String | URL of content to load. |
Emitted when a template HTTP request yields an erroneous response (status < 200 || status > 299)
Param | Type | Details |
---|---|---|
angularEvent | Object | Synthetic event object. |
src | String | URL of content to load. |
© 2010–2017 Google, Inc.
Licensed under the Creative Commons Attribution License 4.0.
https://code.angularjs.org/1.5.11/docs/api/ng/directive/ngInclude