Skip to content

Commit b88f1a6

Browse files
committed
fix($animate): insert elements at the start of the parent container instead of at the end
With 1.2.x, $animate.enter and $animate.move both insert the element at the end of the provided parent container element when only the parent element is provided. If an after element is provided then they will place the inserted element after that one. This works fine, but there is no way to place an item at the top of the provided parent container using both these functions. Closes angular#4934 Closes angular#6275 BREAKING CHANGE: $animate will no longer default the after parameter to the last element of the parent container. Instead, when after is not specified, the new element will be inserted as the first child of the parent container. To update existing code change any instances of $animate.enter() or $animate.move() from: $animate.enter(element, parent); to: $animate.enter(element, parent, angular.element(parent[0].lastChild));
1 parent 47384bc commit b88f1a6

File tree

2 files changed

+19
-10
lines changed

2 files changed

+19
-10
lines changed

src/ng/animate.js

+6-10
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,9 @@ var $AnimateProvider = ['$provide', function($provide) {
111111
* @ngdoc method
112112
* @name $animate#enter
113113
* @function
114-
* @description Inserts the element into the DOM either after the `after` element or within
115-
* the `parent` element. Once complete, the done() callback will be fired (if provided).
114+
* @description Inserts the element into the DOM either after the `after` element or
115+
* as the first child within the `parent` element. Once complete, the done() callback
116+
* will be fired (if provided).
116117
* @param {DOMElement} element the element which will be inserted into the DOM
117118
* @param {DOMElement} parent the parent element which will append the element as
118119
* a child (if the after element is not present)
@@ -122,14 +123,9 @@ var $AnimateProvider = ['$provide', function($provide) {
122123
* inserted into the DOM
123124
*/
124125
enter : function(element, parent, after, done) {
125-
if (after) {
126-
after.after(element);
127-
} else {
128-
if (!parent || !parent[0]) {
129-
parent = after.parent();
130-
}
131-
parent.append(element);
132-
}
126+
after
127+
? after.after(element)
128+
: parent.prepend(element);
133129
async(done);
134130
},
135131

test/ng/animateSpec.js

+13
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,19 @@ describe("$animate", function() {
1515
expect(element.contents().length).toBe(1);
1616
}));
1717

18+
it("should enter the element to the start of the parent container",
19+
inject(function($animate, $compile, $rootScope) {
20+
21+
for(var i = 0; i < 5; i++) {
22+
element.append(jqLite('<div> ' + i + '</div>'));
23+
}
24+
25+
var child = jqLite('<div>first</div>');
26+
$animate.enter(child, element);
27+
28+
expect(element.text()).toEqual('first 0 1 2 3 4');
29+
}));
30+
1831
it("should remove the element at the end of leave animation", inject(function($animate, $compile, $rootScope) {
1932
var child = $compile('<div></div>')($rootScope);
2033
element.append(child);

0 commit comments

Comments
 (0)