@@ -9,10 +9,11 @@ function $ViewDirective( $state, $compile, $controller, $injector, $an
9
9
terminal : true ,
10
10
link : function ( scope , element , attr ) {
11
11
var viewScope , viewLocals ,
12
+ initialContent = element . contents ( ) ,
12
13
name = attr [ directive . name ] || attr . name || '' ,
13
14
onloadExp = attr . onload || '' ,
14
15
animate = isDefined ( $animator ) && $animator ( scope , attr ) ;
15
-
16
+
16
17
// Find the details of the parent view directive (if any) and use it
17
18
// to derive our own qualified view name, then hang our own details
18
19
// off the DOM so child directives can find it.
@@ -28,11 +29,15 @@ function $ViewDirective( $state, $compile, $controller, $injector, $an
28
29
var locals = $state . $current && $state . $current . locals [ name ] ;
29
30
if ( locals === viewLocals ) return ; // nothing to do
30
31
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
+ }
35
38
39
+ // Destroy previous view scope
40
+ if ( viewScope ) {
36
41
viewScope . $destroy ( ) ;
37
42
viewScope = null ;
38
43
}
@@ -67,6 +72,13 @@ function $ViewDirective( $state, $compile, $controller, $injector, $an
67
72
} else {
68
73
viewLocals = null ;
69
74
view . state = null ;
75
+
76
+ // Restore empty view
77
+ if ( doAnimate ) {
78
+ animate . enter ( initialContent , element ) ;
79
+ } else {
80
+ element . html ( initialContent ) ;
81
+ }
70
82
}
71
83
}
72
84
}
0 commit comments