问题
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