Skip to content

Commit bbcb714

Browse files
committed
fix($animate): insert elements at the start of the parent container instead of at the end
$animate.enter and $animate.move both insert the element at the end of the provided parent container element. 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. This commit fixes this issue. BREAKING CHANGE: $animate will no longer place elements at the end of the parent container when enter or move is used with a parent container element. Any former directives that rely on this feature must be slightly modified to work around this fix. The same effect can be achieved by finding the final element in the parent container list and using that as the after element (which is the 3rd argument in the enter and move $animate operations). Closes angular#4934 Closes angular#6275
1 parent 47384bc commit bbcb714

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)