AngularJS: pushing new data to $scope.myList, top

别来无恙 提交于 2019-12-23 13:39:12

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!