angular / angular.js

AngularJS - HTML enhanced for web apps!
https://angularjs.org
MIT License
58.8k stars 27.49k forks source link

AngularJS 1.3.0 ngRepeat Prints Objects from Array In Reverse #9831

Closed alex-19841 closed 10 years ago

alex-19841 commented 10 years ago

I upgraded AngularJS from 1.2 version to 1.3.0 and noticed that ngRepeat started to print object from array in reverse. Filter example:

return function (people) {
       if (!angular.isArray(people))
           return people;

    var results = [];

    var members = [];
    var spouses = [];

    var everyoneElseUnOrdered = [];
    var everyoneElseOrderedByBirthDate = [];

    angular.forEach(people, function (person) {
        var relationshipType = $filter('relationship')(person.Relationship, person.Gender);

        switch (relationshipType) {
            case 'Member':
                members.push(person);
                break;
            case 'Husband', 'Wife':
                spouses.push(person);
                break;
            default:
                everyoneElseUnOrdered.push(person);
        }
    });

    everyoneElseOrderedByBirthDate = $filter('orderBy')(everyoneElseUnOrdered, function (person) {
        var date = new Date(person.BirthDate);
        return date;
    });

    angular.forEach(members, function (member) {
        results.push(member);
    });

    angular.forEach(spouses, function (spouse) {
        results.push(spouse);
    });

    angular.forEach(everyoneElseOrderedByBirthDate, function (person) {
        results.push(person);
    });

    return results;
};

When filter applied to ngRepeat "Member" will be at the very bottom instead of top. Example: child child wife member

But with 1.2.* ngRepeat prints in order

member wife child child

caitp commented 10 years ago

I think this is a dupe of #9566

m-amr commented 10 years ago

Could you push the full code on Github and post the link.

caitp commented 10 years ago

closing because it's a dupe --- but the original bug is probably going to be fixed in 1.3.2, or sooner if someone else greenlights the patch.

alex-19841 commented 10 years ago

caitp,

Thanks!