Skip to content

Commit

Permalink
Fixed issues angular-ui#142 (removing ui-view content at the first load)
Browse files Browse the repository at this point in the history
  • Loading branch information
adambabik committed May 24, 2013
1 parent 4f8f5ab commit 1336d9b
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions src/viewDirective.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ function $ViewDirective( $state, $compile, $controller, $injector, $an
terminal: true,
link: function(scope, element, attr) {
var viewScope, viewLocals,
initialContent = element.contents(),
name = attr[directive.name] || attr.name || '',
onloadExp = attr.onload || '',
animate = isDefined($animator) && $animator(scope, attr);

// Find the details of the parent view directive (if any) and use it
// to derive our own qualified view name, then hang our own details
// off the DOM so child directives can find it.
Expand All @@ -28,11 +29,15 @@ function $ViewDirective( $state, $compile, $controller, $injector, $an
var locals = $state.$current && $state.$current.locals[name];
if (locals === viewLocals) return; // nothing to do

// Destroy previous view scope and remove content (if any)
if (viewScope) {
if (animate && doAnimate) animate.leave(element.contents(), element);
else element.html('');
// Remove existing content
if (animate && doAnimate) {
animate.leave(element.contents(), element);
} else {
element.html('');
}

// Destroy previous view scope
if (viewScope) {
viewScope.$destroy();
viewScope = null;
}
Expand Down Expand Up @@ -67,6 +72,13 @@ function $ViewDirective( $state, $compile, $controller, $injector, $an
} else {
viewLocals = null;
view.state = null;

// Restore initial view
if (doAnimate) {
animate.enter(initialContent, element);
} else {
element.html(initialContent);
}
}
}
}
Expand Down

0 comments on commit 1336d9b

Please sign in to comment.