ngView
is a directive that complements the $route service by
including the rendered template of the current route into the main layout (index.html
) file.
Every time the current route changes, the included view changes with it according to the
configuration of the $route
service.
Requires the ngRoute
module to be installed.
If ngView
is contained in an asynchronously loaded template (e.g. in another
directive's templateUrl or in a template loaded using ngInclude
), then you need to
make sure that $route
is instantiated in time to capture the initial
$locationChangeStart
event and load the appropriate view. One way to achieve this
is to have it as a dependency in a .run
block:
myModule.run(['$route', function() {}]);
<ng-view
[onload="string"]
[autoscroll="string"]>
...
</ng-view>
<ANY
[onload="string"]
[autoscroll="string"]>
...
</ANY>
<ANY class="[onload: string;] [autoscroll: string;]"> ... </ANY>
Animation | Occurs |
---|---|
enter | when the new element is inserted to the DOM |
leave | when the old element is removed from to the DOM |
The enter and leave animation occur concurrently.
Click here to learn more about the steps involved in the animation.Param | Type | Details |
---|---|---|
onload
(optional)
|
string |
Expression to evaluate whenever the view updates. |
autoscroll
(optional)
|
string |
Whether
|
Emitted every time the ngView content is reloaded.
<div ng-controller="MainCtrl as main">
Choose:
<a href="Book/Moby">Moby</a> |
<a href="Book/Moby/ch/1">Moby: Ch1</a> |
<a href="Book/Gatsby">Gatsby</a> |
<a href="Book/Gatsby/ch/4?key=value">Gatsby: Ch4</a> |
<a href="Book/Scarlet">Scarlet Letter</a><br/>
<div class="view-animate-container">
<div ng-view class="view-animate"></div>
</div>
<hr />
<pre>$location.path() = {{main.$location.path()}}</pre>
<pre>$route.current.templateUrl = {{main.$route.current.templateUrl}}</pre>
<pre>$route.current.params = {{main.$route.current.params}}</pre>
<pre>$routeParams = {{main.$routeParams}}</pre>
</div>