AngularJS:推新数据$ scope.myList,顶 [英] AngularJS: pushing new data to $scope.myList, top

查看:132
本文介绍了AngularJS:推新数据$ scope.myList,顶的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是新的内容添加到右侧 $ scope.myList = [] ,当我想要操作DOM?

What is the right to add new content to $scope.myList = [], when I want to manipulate the DOM?

我试过 $ scope.myList.push(数据); ,其中在最后添加新的数据,因此,在HTML模板的结尾里面NG-中继器。我希望它在上面。
不印字功能将重新排列阵列和更新的所有元素。

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.

新建棱角分明。

编辑:
也许不是问题应该是:我应该如何添加新的内容动态地到我的模板的顶部

Maybe instead the question should be: How should I add new content dynamically into the top of my template?

推荐答案

每当你想prePEND到一个数组,你将重新排列整个数组。如果你能决定了数据格式,我建议你添加一个入口号 ID 数据字段和使用的角过滤器放置新项目的顶端。

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.

看看这个plunker

这篇关于AngularJS:推新数据$ scope.myList,顶的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆