24
24
* access on some browsers)
25
25
*
26
26
* @animations
27
- * enter - happens just after the ngInclude contents change and a new DOM element is created and injected into the ngInclude container
28
- * leave - happens just after the ngInclude contents change and just before the former contents are removed from the DOM
27
+ * enter - animation is used to bring new content into the browser.
28
+ * leave - animation is used to animate existing content away.
29
+ *
30
+ * The enter and leave animation occur concurrently.
29
31
*
30
32
* @scope
31
33
*
49
51
</select>
50
52
url of the template: <tt>{{template.url}}</tt>
51
53
<hr/>
52
- <div class="example-animate-container"
53
- ng-include="template.url"
54
- ng-animate="{enter: 'example-enter', leave: 'example-leave'}"> </div>
54
+ <div class="example-animate-container">
55
+ <div class="include-example" ng-include="template.url"></div>
56
+ </div>
55
57
</div>
56
58
</file>
57
59
<file name="script.js">
63
65
}
64
66
</file>
65
67
<file name="template1.html">
66
- <div> Content of template1.html</div>
68
+ Content of template1.html
67
69
</file>
68
70
<file name="template2.html">
69
- <div> Content of template2.html</div>
71
+ Content of template2.html
70
72
</file>
71
73
<file name="animations.css">
72
- .example-leave,
73
- .example-enter {
74
+ .include-example.ng-enter, .include-example.ng-leave {
74
75
-webkit-transition:all cubic-bezier(0.250, 0.460, 0.450, 0.940) 0.5s;
75
76
-moz-transition:all cubic-bezier(0.250, 0.460, 0.450, 0.940) 0.5s;
76
77
-ms-transition:all cubic-bezier(0.250, 0.460, 0.450, 0.940) 0.5s;
82
83
left:0;
83
84
right:0;
84
85
bottom:0;
85
- }
86
-
87
- .example-animate-container > * {
88
86
display:block;
89
87
padding:10px;
90
88
}
91
89
92
- .example-enter {
90
+ .include- example.ng -enter {
93
91
top:-50px;
94
92
}
95
- .example-enter.example -enter-active {
93
+ .include- example.ng -enter.ng -enter-active {
96
94
top:0;
97
95
}
98
96
99
- .example-leave {
97
+ .include- example.ng -leave {
100
98
top:0;
101
99
}
102
- .example-leave.example -leave-active {
100
+ .include- example.ng -leave.ng -leave-active {
103
101
top:50px;
104
102
}
105
103
</file>
115
113
});
116
114
it('should change to blank', function() {
117
115
select('template').option('');
118
- expect(element('.doc-example-live [ng-include]').text()).toEqual('' );
116
+ expect(element('.doc-example-live [ng-include]')).toBe(undefined );
119
117
});
120
118
</file>
121
119
</example>
@@ -145,21 +143,26 @@ var ngIncludeDirective = ['$http', '$templateCache', '$anchorScroll', '$compile'
145
143
return {
146
144
restrict : 'ECA' ,
147
145
terminal : true ,
148
- compile : function ( element , attr ) {
146
+ transclude : 'element' ,
147
+ compile : function ( element , attr , transclusion ) {
149
148
var srcExp = attr . ngInclude || attr . src ,
150
149
onloadExp = attr . onload || '' ,
151
150
autoScrollExp = attr . autoscroll ;
152
151
153
- return function ( scope , element , attr ) {
152
+ return function ( scope , $ element) {
154
153
var changeCounter = 0 ,
155
- childScope ;
154
+ currentScope ,
155
+ currentElement ;
156
156
157
- var clearContent = function ( ) {
158
- if ( childScope ) {
159
- childScope . $destroy ( ) ;
160
- childScope = null ;
157
+ var cleanupLastIncludeContent = function ( ) {
158
+ if ( currentScope ) {
159
+ currentScope . $destroy ( ) ;
160
+ currentScope = null ;
161
+ }
162
+ if ( currentElement ) {
163
+ $animate . leave ( currentElement ) ;
164
+ currentElement = null ;
161
165
}
162
- $animate . leave ( element . contents ( ) ) ;
163
166
} ;
164
167
165
168
scope . $watch ( $sce . parseAsResourceUrl ( srcExp ) , function ngIncludeWatchAction ( src ) {
@@ -168,28 +171,31 @@ var ngIncludeDirective = ['$http', '$templateCache', '$anchorScroll', '$compile'
168
171
if ( src ) {
169
172
$http . get ( src , { cache : $templateCache } ) . success ( function ( response ) {
170
173
if ( thisChangeId !== changeCounter ) return ;
174
+ var newScope = scope . $new ( ) ;
171
175
172
- if ( childScope ) childScope . $destroy ( ) ;
173
- childScope = scope . $new ( ) ;
174
- $animate . leave ( element . contents ( ) ) ;
176
+ transclusion ( newScope , function ( clone ) {
177
+ cleanupLastIncludeContent ( ) ;
175
178
176
- var contents = jqLite ( '<div/>' ) . html ( response ) . contents ( ) ;
179
+ currentScope = newScope ;
180
+ currentElement = clone ;
177
181
178
- $animate . enter ( contents , element ) ;
179
- $compile ( contents ) ( childScope ) ;
182
+ currentElement . html ( response ) ;
183
+ $animate . enter ( currentElement , null , $element ) ;
184
+ $compile ( currentElement . contents ( ) ) ( currentScope ) ;
180
185
181
- if ( isDefined ( autoScrollExp ) && ( ! autoScrollExp || scope . $eval ( autoScrollExp ) ) ) {
182
- $anchorScroll ( ) ;
183
- }
186
+ if ( isDefined ( autoScrollExp ) && ( ! autoScrollExp || scope . $eval ( autoScrollExp ) ) ) {
187
+ $anchorScroll ( ) ;
188
+ }
184
189
185
- childScope . $emit ( '$includeContentLoaded' ) ;
186
- scope . $eval ( onloadExp ) ;
190
+ currentScope . $emit ( '$includeContentLoaded' ) ;
191
+ scope . $eval ( onloadExp ) ;
192
+ } ) ;
187
193
} ) . error ( function ( ) {
188
- if ( thisChangeId === changeCounter ) clearContent ( ) ;
194
+ if ( thisChangeId === changeCounter ) cleanupLastIncludeContent ( ) ;
189
195
} ) ;
190
196
scope . $emit ( '$includeContentRequested' ) ;
191
197
} else {
192
- clearContent ( ) ;
198
+ cleanupLastIncludeContent ( ) ;
193
199
}
194
200
} ) ;
195
201
} ;
0 commit comments