2424 * access on some browsers)
2525 *
2626 * @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.
2931 *
3032 * @scope
3133 *
4951 </select>
5052 url of the template: <tt>{{template.url}}</tt>
5153 <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>
5557 </div>
5658 </file>
5759 <file name="script.js">
6365 }
6466 </file>
6567 <file name="template1.html">
66- <div> Content of template1.html</div>
68+ Content of template1.html
6769 </file>
6870 <file name="template2.html">
69- <div> Content of template2.html</div>
71+ Content of template2.html
7072 </file>
7173 <file name="animations.css">
72- .example-leave,
73- .example-enter {
74+ .include-example.ng-enter, .include-example.ng-leave {
7475 -webkit-transition:all cubic-bezier(0.250, 0.460, 0.450, 0.940) 0.5s;
7576 -moz-transition:all cubic-bezier(0.250, 0.460, 0.450, 0.940) 0.5s;
7677 -ms-transition:all cubic-bezier(0.250, 0.460, 0.450, 0.940) 0.5s;
8283 left:0;
8384 right:0;
8485 bottom:0;
85- }
86-
87- .example-animate-container > * {
8886 display:block;
8987 padding:10px;
9088 }
9189
92- .example-enter {
90+ .include- example.ng -enter {
9391 top:-50px;
9492 }
95- .example-enter.example -enter-active {
93+ .include- example.ng -enter.ng -enter-active {
9694 top:0;
9795 }
9896
99- .example-leave {
97+ .include- example.ng -leave {
10098 top:0;
10199 }
102- .example-leave.example -leave-active {
100+ .include- example.ng -leave.ng -leave-active {
103101 top:50px;
104102 }
105103 </file>
115113 });
116114 it('should change to blank', function() {
117115 select('template').option('');
118- expect(element('.doc-example-live [ng-include]').text()).toEqual('' );
116+ expect(element('.doc-example-live [ng-include]')).toBe(undefined );
119117 });
120118 </file>
121119 </example>
@@ -145,21 +143,26 @@ var ngIncludeDirective = ['$http', '$templateCache', '$anchorScroll', '$compile'
145143 return {
146144 restrict : 'ECA' ,
147145 terminal : true ,
148- compile : function ( element , attr ) {
146+ transclude : 'element' ,
147+ compile : function ( element , attr , transclusion ) {
149148 var srcExp = attr . ngInclude || attr . src ,
150149 onloadExp = attr . onload || '' ,
151150 autoScrollExp = attr . autoscroll ;
152151
153- return function ( scope , element , attr ) {
152+ return function ( scope , $ element) {
154153 var changeCounter = 0 ,
155- childScope ;
154+ currentScope ,
155+ currentElement ;
156156
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 ;
161165 }
162- $animate . leave ( element . contents ( ) ) ;
163166 } ;
164167
165168 scope . $watch ( $sce . parseAsResourceUrl ( srcExp ) , function ngIncludeWatchAction ( src ) {
@@ -168,28 +171,31 @@ var ngIncludeDirective = ['$http', '$templateCache', '$anchorScroll', '$compile'
168171 if ( src ) {
169172 $http . get ( src , { cache : $templateCache } ) . success ( function ( response ) {
170173 if ( thisChangeId !== changeCounter ) return ;
174+ var newScope = scope . $new ( ) ;
171175
172- if ( childScope ) childScope . $destroy ( ) ;
173- childScope = scope . $new ( ) ;
174- $animate . leave ( element . contents ( ) ) ;
176+ transclusion ( newScope , function ( clone ) {
177+ cleanupLastIncludeContent ( ) ;
175178
176- var contents = jqLite ( '<div/>' ) . html ( response ) . contents ( ) ;
179+ currentScope = newScope ;
180+ currentElement = clone ;
177181
178- $animate . enter ( contents , element ) ;
179- $compile ( contents ) ( childScope ) ;
182+ currentElement . html ( response ) ;
183+ $animate . enter ( currentElement , null , $element ) ;
184+ $compile ( currentElement . contents ( ) ) ( currentScope ) ;
180185
181- if ( isDefined ( autoScrollExp ) && ( ! autoScrollExp || scope . $eval ( autoScrollExp ) ) ) {
182- $anchorScroll ( ) ;
183- }
186+ if ( isDefined ( autoScrollExp ) && ( ! autoScrollExp || scope . $eval ( autoScrollExp ) ) ) {
187+ $anchorScroll ( ) ;
188+ }
184189
185- childScope . $emit ( '$includeContentLoaded' ) ;
186- scope . $eval ( onloadExp ) ;
190+ currentScope . $emit ( '$includeContentLoaded' ) ;
191+ scope . $eval ( onloadExp ) ;
192+ } ) ;
187193 } ) . error ( function ( ) {
188- if ( thisChangeId === changeCounter ) clearContent ( ) ;
194+ if ( thisChangeId === changeCounter ) cleanupLastIncludeContent ( ) ;
189195 } ) ;
190196 scope . $emit ( '$includeContentRequested' ) ;
191197 } else {
192- clearContent ( ) ;
198+ cleanupLastIncludeContent ( ) ;
193199 }
194200 } ) ;
195201 } ;
0 commit comments