Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 9956bae

Browse files
committedMay 2, 2013
fix(ngView): accidentally compiling leaving content
closes: #2304
1 parent 1d8e11d commit 9956bae

File tree

3 files changed

+56
-10
lines changed

3 files changed

+56
-10
lines changed
 

‎src/ng/animator.js

+9-6
Original file line numberDiff line numberDiff line change
@@ -272,14 +272,17 @@ var $AnimatorProvider = function() {
272272

273273
var durationKey = 'Duration';
274274
var duration = 0;
275+
275276
//we want all the styles defined before and after
276277
forEach(element, function(element) {
277-
var globalStyles = $window.getComputedStyle(element) || {};
278-
duration = Math.max(
279-
parseFloat(globalStyles[w3cTransitionProp + durationKey]) ||
280-
parseFloat(globalStyles[vendorTransitionProp + durationKey]) ||
281-
0,
282-
duration);
278+
if (element.nodeType == 1) {
279+
var globalStyles = $window.getComputedStyle(element) || {};
280+
duration = Math.max(
281+
parseFloat(globalStyles[w3cTransitionProp + durationKey]) ||
282+
parseFloat(globalStyles[vendorTransitionProp + durationKey]) ||
283+
0,
284+
duration);
285+
}
283286
});
284287
$window.setTimeout(done, duration * 1000);
285288
} else {

‎src/ng/directive/ngView.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -194,9 +194,10 @@ var ngViewDirective = ['$http', '$templateCache', '$route', '$anchorScroll', '$c
194194

195195
if (template) {
196196
clearContent();
197-
animate.enter(jqLite('<div></div>').html(template).contents(), element);
197+
var enterElements = jqLite('<div></div>').html(template).contents();
198+
animate.enter(enterElements, element);
198199

199-
var link = $compile(element.contents()),
200+
var link = $compile(enterElements),
200201
current = $route.current,
201202
controller;
202203

‎test/ng/directive/ngViewSpec.js

+44-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
describe('ngView', function() {
44
var element;
55

6-
beforeEach(module(function() {
6+
beforeEach(module(function($provide) {
7+
$provide.value('$window', angular.mock.createMockWindow());
78
return function($rootScope, $compile, $animator) {
89
element = $compile('<ng:view onload="load()"></ng:view>')($rootScope);
910
$animator.enabled(true);
@@ -621,5 +622,46 @@ describe('ngView', function() {
621622
}
622623
}));
623624

625+
626+
it('should not double compile when route changes', function() {
627+
module(function($routeProvider, $animationProvider, $provide) {
628+
$routeProvider.when('/foo', {template: '<div ng-repeat="i in [1,2]">{{i}}</div>'});
629+
$routeProvider.when('/bar', {template: '<div ng-repeat="i in [3,4]">{{i}}</div>'});
630+
$animationProvider.register('my-animation-leave', function() {
631+
return {
632+
start: function(element, done) {
633+
done();
634+
}
635+
};
636+
});
637+
});
638+
639+
inject(function($rootScope, $compile, $location, $route, $window, $rootElement, $sniffer) {
640+
element = $compile(html('<ng:view onload="load()" ng-animate="\'my-animation\'"></ng:view>'))($rootScope);
641+
642+
$location.path('/foo');
643+
$rootScope.$digest();
644+
if ($sniffer.supportsTransitions) {
645+
$window.setTimeout.expect(1).process();
646+
$window.setTimeout.expect(0).process();
647+
}
648+
expect(element.text()).toEqual('12');
649+
650+
$location.path('/bar');
651+
$rootScope.$digest();
652+
expect(n(element.text())).toEqual('1234');
653+
if ($sniffer.supportsTransitions) {
654+
$window.setTimeout.expect(1).process();
655+
$window.setTimeout.expect(1).process();
656+
} else {
657+
$window.setTimeout.expect(1).process();
658+
}
659+
expect(element.text()).toEqual('34');
660+
661+
function n(text) {
662+
return text.replace(/\r\n/m, '').replace(/\r\n/m, '');
663+
}
664+
});
665+
});
624666
});
625-
});
667+
});

0 commit comments

Comments
 (0)
This repository has been archived.