knowhow-server
Version:
A personal workflow engine that can manage and use any network connected host
204 lines (191 loc) • 9.4 kB
HTML
<a href="http://github.com/angular/angular.js/tree/v1.2.9/src/ngRoute/directive/ngView.js#L7" class="view-source btn btn-action"><i class="icon-zoom-in"> </i> View source</a><a href="http://github.com/angular/angular.js/edit/master/src/ngRoute/directive/ngView.js" class="improve-docs btn btn-primary"><i class="icon-edit"> </i> Improve this doc</a><h1><code ng:non-bindable="">ngView</code>
<div><span class="hint">directive in module <code ng:non-bindable="">ngRoute</code>
</span>
</div>
</h1>
<div><h2 id="description">Description</h2>
<div class="description"><div class="ngroute-directive-page ngroute-directive-ngview-page"><h3 id="description_overview">Overview</h3>
<p><code>ngView</code> is a directive that complements the <a href="api/ngRoute.$route">$route</a> service by
including the rendered template of the current route into the main layout (<code>index.html</code>) file.
Every time the current route changes, the included view changes with it according to the
configuration of the <code>$route</code> service.</p>
<p>Requires the <a href="api/ngRoute"><code>ngRoute</code></a> module to be installed.</p>
</div></div>
<h2 id="usage">Usage</h2>
<div class="usage"><p>This directive can be used as custom element, but be aware of <a href="guide/ie">IE restrictions</a>.</p>as element:<pre class="prettyprint linenums"><ng-view
[onload="{string}"]
[autoscroll="{string}"]>
</ng-view></pre>
as attribute<pre class="prettyprint linenums"><ANY ng-view
[onload="{string}"]
[autoscroll="{string}"]>
...
</ANY></pre>
as class<pre class="prettyprint linenums"><ANY class="ng-view [onload: {string};] [autoscroll: {string};]">
...
</ANY></pre>
<h3 id="usage_directive-info">Directive info</h3>
<div class="directive-info"><ul><li>This directive creates new scope.</li>
<li>This directive executes at priority level 400.</li>
</ul>
</div>
<h3 id="usage_animations">Animations</h3>
<div class="animations"><ul><li>enter - animation is used to bring new content into the browser.</li><li>leave - animation is used to animate existing content away.</li><li></li><li>The enter and leave animation occur concurrently.</li></ul></div>
<a href="api/ngAnimate.$animate">Click here</a> to learn more about the steps involved in the animation.<h4 id="usage_animations_parameters">Parameters</h4><table class="variables-matrix table table-bordered table-striped"><thead><tr><th>Param</th><th>Type</th><th>Details</th></tr></thead><tbody><tr><td>onload <div><em>(optional)</em></div></td><td><a href="" class="label type-hint type-hint-string">string</a></td><td><div class="ngroute-directive-page ngroute-directive-ngview-page"><p>Expression to evaluate whenever the view updates.</p>
</div></td></tr><tr><td>autoscroll <div><em>(optional)</em></div></td><td><a href="" class="label type-hint type-hint-string">string</a></td><td><div class="ngroute-directive-page ngroute-directive-ngview-page"><p>Whether <code>ngView</code> should call <a href="api/ng.$anchorScroll"><code>$anchorScroll</code></a> to scroll the viewport after the view is updated.</p>
<ul>
<li>If the attribute is not set, disable scrolling.</li>
<li>If the attribute is set without value, enable scrolling.</li>
<li>Otherwise enable scrolling only if the <code>autoscroll</code> attribute value evaluated
as an expression yields a truthy value.</li>
</ul>
</div></td></tr></tbody></table></div>
<div class="member event"><h2 id="events">Events</h2>
<ul class="events"><li><h3 id="events_$viewcontentloaded">$viewContentLoaded</h3>
<div class="$viewcontentloaded"><div class="ngroute-directive-page ngroute-directive-ngview-viewcontentloaded-page"><p>Emitted every time the ngView content is reloaded.</p>
</div><div class="inline"><h4 id="events_$viewcontentloaded_type">Type:</h4>
<div class="type">emit</div>
</div>
<div class="inline"><h4 id="events_$viewcontentloaded_target">Target:</h4>
<div class="target">the current ngView scope</div>
</div>
</div>
</li>
</ul>
</div>
<h2 id="example">Example</h2>
<div class="example"><div class="ngroute-directive-page ngroute-directive-ngview-page"><h4 id="example_source">Source</h4>
<div source-edit="ngViewExample" source-edit-deps="angular.js angular-animate.js angular-route.js script.js" source-edit-html="index.html-166 book.html chapter.html" source-edit-css="animations.css" source-edit-js="script.js-167" source-edit-json="" source-edit-unit="" source-edit-scenario="scenario.js-168" source-edit-protractor=""></div>
<div class="tabbable"><div class="tab-pane" title="index.html">
<pre class="prettyprint linenums" ng-set-text="index.html-166" ng-html-wrap="ngViewExample angular.js angular-animate.js angular-route.js script.js"></pre>
<script type="text/ng-template" id="index.html-166">
<div ng-controller="MainCntl 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>$route.current.scope.name = {{main.$route.current.scope.name}}</pre>
<pre>$routeParams = {{main.$routeParams}}</pre>
</div>
</script>
</div>
<div class="tab-pane" title="book.html">
<pre class="prettyprint linenums" ng-set-text="book.html"></pre>
<script type="text/ng-template" id="book.html">
<div>
controller: {{book.name}}<br />
Book Id: {{book.params.bookId}}<br />
</div>
</script>
</div>
<div class="tab-pane" title="chapter.html">
<pre class="prettyprint linenums" ng-set-text="chapter.html"></pre>
<script type="text/ng-template" id="chapter.html">
<div>
controller: {{chapter.name}}<br />
Book Id: {{chapter.params.bookId}}<br />
Chapter Id: {{chapter.params.chapterId}}
</div>
</script>
</div>
<div class="tab-pane" title="animations.css">
<pre class="prettyprint linenums" ng-set-text="animations.css"></pre>
<style type="text/css" id="animations.css">
.view-animate-container {
position:relative;
height:100px;
position:relative;
background:white;
border:1px solid black;
height:40px;
overflow:hidden;
}
.view-animate {
padding:10px;
}
.view-animate.ng-enter, .view-animate.ng-leave {
-webkit-transition:all cubic-bezier(0.250, 0.460, 0.450, 0.940) 1.5s;
transition:all cubic-bezier(0.250, 0.460, 0.450, 0.940) 1.5s;
display:block;
width:100%;
border-left:1px solid black;
position:absolute;
top:0;
left:0;
right:0;
bottom:0;
padding:10px;
}
.view-animate.ng-enter {
left:100%;
}
.view-animate.ng-enter.ng-enter-active {
left:0;
}
.view-animate.ng-leave.ng-leave-active {
left:-100%;
}
</style>
</div>
<div class="tab-pane" title="script.js">
<pre class="prettyprint linenums" ng-set-text="script.js-167"></pre>
<script type="text/ng-template" id="script.js-167">
angular.module('ngViewExample', ['ngRoute', 'ngAnimate'],
function($routeProvider, $locationProvider) {
$routeProvider.when('/Book/:bookId', {
templateUrl: 'book.html',
controller: BookCntl,
controllerAs: 'book'
});
$routeProvider.when('/Book/:bookId/ch/:chapterId', {
templateUrl: 'chapter.html',
controller: ChapterCntl,
controllerAs: 'chapter'
});
// configure html5 to get links working on jsfiddle
$locationProvider.html5Mode(true);
});
function MainCntl($route, $routeParams, $location) {
this.$route = $route;
this.$location = $location;
this.$routeParams = $routeParams;
}
function BookCntl($routeParams) {
this.name = "BookCntl";
this.params = $routeParams;
}
function ChapterCntl($routeParams) {
this.name = "ChapterCntl";
this.params = $routeParams;
}
</script>
</div>
<div class="tab-pane" title="ngScenario e2e test">
<pre class="prettyprint linenums" ng-set-text="scenario.js-168"></pre>
<script type="text/ng-template" id="scenario.js-168">
it('should load and compile correct template', function() {
element('a:contains("Moby: Ch1")').click();
var content = element('.doc-example-live [ng-view]').text();
expect(content).toMatch(/controller\: ChapterCntl/);
expect(content).toMatch(/Book Id\: Moby/);
expect(content).toMatch(/Chapter Id\: 1/);
element('a:contains("Scarlet")').click();
content = element('.doc-example-live [ng-view]').text();
expect(content).toMatch(/controller\: BookCntl/);
expect(content).toMatch(/Book Id\: Scarlet/);
});
</script>
</div>
</div><div class="pull-right"> <button class="btn btn-primary" ng-click="animationsOff=true" ng-hide="animationsOff">Animations on</button> <button class="btn btn-primary disabled" ng-click="animationsOff=false" ng-show="animationsOff">Animations off</button></div><h4 id="example_demo">Demo</h4>
<div class="well doc-example-live animate-container" ng-class="{'animations-off':animationsOff == true}" ng-embed-app="ngViewExample" ng-set-html="index.html-166" ng-eval-javascript="script.js-167"></div>
</div></div>
</div>