diff --git a/src/ng/animate.js b/src/ng/animate.js index 785d1dfa1d1f..34f20f004025 100644 --- a/src/ng/animate.js +++ b/src/ng/animate.js @@ -111,8 +111,9 @@ var $AnimateProvider = ['$provide', function($provide) { * @ngdoc method * @name $animate#enter * @function - * @description Inserts the element into the DOM either after the `after` element or within - * the `parent` element. Once complete, the done() callback will be fired (if provided). + * @description Inserts the element into the DOM either after the `after` element or + * as the first child within the `parent` element. Once complete, the done() callback + * will be fired (if provided). * @param {DOMElement} element the element which will be inserted into the DOM * @param {DOMElement} parent the parent element which will append the element as * a child (if the after element is not present) @@ -122,14 +123,9 @@ var $AnimateProvider = ['$provide', function($provide) { * inserted into the DOM */ enter : function(element, parent, after, done) { - if (after) { - after.after(element); - } else { - if (!parent || !parent[0]) { - parent = after.parent(); - } - parent.append(element); - } + after + ? after.after(element) + : parent.prepend(element); async(done); }, diff --git a/test/ng/animateSpec.js b/test/ng/animateSpec.js index e982862aed60..b9dd1493330e 100644 --- a/test/ng/animateSpec.js +++ b/test/ng/animateSpec.js @@ -15,6 +15,19 @@ describe("$animate", function() { expect(element.contents().length).toBe(1); })); + it("should enter the element to the start of the parent container", + inject(function($animate, $compile, $rootScope) { + + for(var i = 0; i < 5; i++) { + element.append(jqLite('
' + i + '
')); + } + + var child = jqLite('
first
'); + $animate.enter(child, element); + + expect(element.text()).toEqual('first 0 1 2 3 4'); + })); + it("should remove the element at the end of leave animation", inject(function($animate, $compile, $rootScope) { var child = $compile('
')($rootScope); element.append(child);