ng-include how to make a orderBy to an object

强颜欢笑 提交于 2019-12-25 09:39:54

问题


I'm aware that Angular filters can only be applied to arrays, not objects

I'm attempting to include templates added dynamically using the following code. All seems to work well until you see the order

What I would like to have this order:

Create Book Address

here is the Plunker


回答1:


Instead of using a key-value object, why not use an array? ng-repeat orders the iteration by the index of the iterated object/array.

FORKED DEMO

  $scope.templates = [
    'create.html',
    'book.html',
    'address.html'
  ];



回答2:


seems like angular will get ng-include by ordering the names according to their name,

so when you use

$scope.templates = 
{
  _address : 'address.html',
  _create : 'create.html',
  _book : 'book.html'
};

ordering template according to their names, then _address comes first _book comes second _create comes third

simple approach to solve

$scope.templates = 
{
  _a_create : 'create.html',
  _b_address : 'address.html',
  _c_book : 'book.html'
};

here is the Plunker



来源:https://stackoverflow.com/questions/27466300/ng-include-how-to-make-a-orderby-to-an-object

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