1
1
2
- $ViewDirective . $inject = [ '$state' , '$compile' , '$controller' , '$animator' , '$anchorScroll' ] ;
3
- function $ViewDirective ( $state , $compile , $controller , $animator , $anchorScroll ) {
2
+ $ViewDirective . $inject = [ '$state' , '$compile' , '$controller' , '$injector' , '$anchorScroll' ] ;
3
+ function $ViewDirective ( $state , $compile , $controller , $injector , $anchorScroll ) {
4
+ // Unfortunately there is no neat way to ask $injector if a service exists
5
+ var $animator ; try { $animator = $injector . get ( '$animator' ) ; } catch ( e ) { /* do nothing */ }
6
+
4
7
var directive = {
5
8
restrict : 'ECA' ,
6
9
terminal : true ,
7
10
link : function ( scope , element , attr ) {
8
11
var viewScope , viewLocals ,
9
12
name = attr [ directive . name ] || attr . name || '' ,
10
13
onloadExp = attr . onload || '' ,
11
- animate = $animator ( scope , attr ) ;
14
+ animate = $animator && $animator ( scope , attr ) ;
12
15
13
16
// Find the details of the parent view directive (if any) and use it
14
17
// to derive our own qualified view name, then hang our own details
@@ -27,7 +30,9 @@ function $ViewDirective( $state, $compile, $controller, $animator, $an
27
30
28
31
// Destroy previous view scope and remove content (if any)
29
32
if ( viewScope ) {
30
- animate . leave ( element . contents ( ) , element ) ;
33
+ if ( animate ) animate . leave ( element . contents ( ) , element ) ;
34
+ else element . html ( '' ) ;
35
+
31
36
viewScope . $destroy ( ) ;
32
37
viewScope = null ;
33
38
}
@@ -36,8 +41,16 @@ function $ViewDirective( $state, $compile, $controller, $animator, $an
36
41
viewLocals = locals ;
37
42
view . state = locals . $$state ;
38
43
39
- animate . enter ( angular . element ( '<div></div>' ) . html ( locals . $template ) . contents ( ) , element ) ;
40
- var link = $compile ( element . contents ( ) ) ;
44
+ var contents ;
45
+ if ( animate ) {
46
+ contents = angular . element ( '<div></div>' ) . html ( locals . $template ) . contents ( ) ;
47
+ animate . enter ( contents , element ) ;
48
+ } else {
49
+ element . html ( locals . $template ) ;
50
+ contents = element . contents ( ) ;
51
+ }
52
+
53
+ var link = $compile ( contents ) ;
41
54
viewScope = scope . $new ( ) ;
42
55
if ( locals . $$controller ) {
43
56
locals . $scope = viewScope ;
0 commit comments