Skip to content

Commit c24a6a6

Browse files
committed
Detect if $animator is present and fall back to plain old DOM manipulation otherwise.
Also call $compile only on the element we're adding, not the container node
1 parent e080bc4 commit c24a6a6

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

src/viewDirective.js

+19-6
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11

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+
47
var directive = {
58
restrict: 'ECA',
69
terminal: true,
710
link: function(scope, element, attr) {
811
var viewScope, viewLocals,
912
name = attr[directive.name] || attr.name || '',
1013
onloadExp = attr.onload || '',
11-
animate = $animator(scope, attr);
14+
animate = $animator && $animator(scope, attr);
1215

1316
// Find the details of the parent view directive (if any) and use it
1417
// to derive our own qualified view name, then hang our own details
@@ -27,7 +30,9 @@ function $ViewDirective( $state, $compile, $controller, $animator, $an
2730

2831
// Destroy previous view scope and remove content (if any)
2932
if (viewScope) {
30-
animate.leave(element.contents(), element);
33+
if (animate) animate.leave(element.contents(), element);
34+
else element.html('');
35+
3136
viewScope.$destroy();
3237
viewScope = null;
3338
}
@@ -36,8 +41,16 @@ function $ViewDirective( $state, $compile, $controller, $animator, $an
3641
viewLocals = locals;
3742
view.state = locals.$$state;
3843

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);
4154
viewScope = scope.$new();
4255
if (locals.$$controller) {
4356
locals.$scope = viewScope;

0 commit comments

Comments
 (0)