UPDATE:
on my html page I'm using as the following:
<section ng-repeat="template in templates">
<ng-include src="template"></ng-include>
</section>
but the problem is that I need specific file in certain order so is there a way I can control the way order is rendering?
I'm trying to orderby an object how do I do that and I have searched online before posting it here.
function MyCtrl($scope) {
$scope.templates = {
template_address: "../template/address.html",
template_book: "../template/book.html",
template_create: "../template/create.html"
};
<div ng-app ng-controller="MyCtrl">
<ul>
<li ng-repeat="(name, path) in templates">{{name}}: {{path}}</li>
</ul>
</div>
http://jsfiddle.net/abuhamzah/6fbpdm9m/
You can't apply a filter to a plain object, only to arrays.
What you can do is define a method in the controller to convert the object to an array:
$scope.templatesAry = function () {
var ary = [];
angular.forEach($scope.templates, function (val, key) {
ary.push({key: key, val: val});
});
return ary;
};
and then filter that:
<li ng-repeat="prop in templatesAry() | orderBy:'-key'">
{{prop.key}}: {{prop.val}}
</li>
Example
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With