Skip to content

Commit cc7bebb

Browse files
committed
Fixed issues angular-ui#142 (removing ui-view content at the first load)
1 parent 4f8f5ab commit cc7bebb

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

src/viewDirective.js

+17-5
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@ function $ViewDirective( $state, $compile, $controller, $injector, $an
99
terminal: true,
1010
link: function(scope, element, attr) {
1111
var viewScope, viewLocals,
12+
initialContent = element.contents(),
1213
name = attr[directive.name] || attr.name || '',
1314
onloadExp = attr.onload || '',
1415
animate = isDefined($animator) && $animator(scope, attr);
15-
16+
1617
// Find the details of the parent view directive (if any) and use it
1718
// to derive our own qualified view name, then hang our own details
1819
// off the DOM so child directives can find it.
@@ -28,11 +29,15 @@ function $ViewDirective( $state, $compile, $controller, $injector, $an
2829
var locals = $state.$current && $state.$current.locals[name];
2930
if (locals === viewLocals) return; // nothing to do
3031

31-
// Destroy previous view scope and remove content (if any)
32-
if (viewScope) {
33-
if (animate && doAnimate) animate.leave(element.contents(), element);
34-
else element.html('');
32+
// Remove existing content
33+
if (animate && doAnimate) {
34+
animate.leave(element.contents(), element);
35+
} else {
36+
element.html('');
37+
}
3538

39+
// Destroy previous view scope
40+
if (viewScope) {
3641
viewScope.$destroy();
3742
viewScope = null;
3843
}
@@ -67,6 +72,13 @@ function $ViewDirective( $state, $compile, $controller, $injector, $an
6772
} else {
6873
viewLocals = null;
6974
view.state = null;
75+
76+
// Restore empty view
77+
if (doAnimate) {
78+
animate.enter(initialContent, element);
79+
} else {
80+
element.html(initialContent);
81+
}
7082
}
7183
}
7284
}

0 commit comments

Comments
 (0)