问题
What is the right to add new content to $scope.myList = [], when I want to manipulate the DOM?
I've tried $scope.myList.push(data);, which adds the new data at the end, and therefore in the end of the HTML-template inside ng-repeater. I want it at the top.
unshift-function will rearrange the array and update all elements.
New to angular.
EDIT: Maybe instead the question should be: How should I add new content dynamically into the top of my template?
回答1:
Whenever you want to prepend to an array, you will be rearranging the entire array. If you can dictate the format of the data, I suggest you add a entry_number or id as a field of the data and use angular filter to place the new items to the top.
Take a look at this plunker.
来源:https://stackoverflow.com/questions/16874636/angularjs-pushing-new-data-to-scope-mylist-top