更新:
在我的html页面上,我使用如下:
<section ng-repeat="template in templates"> <ng-include src="template"></ng-include> </section>
但问题是我需要特定顺序的特定文件,所以有没有办法控制顺序渲染的方式?
我试图通过一个对象来命令我该如何做到这一点,我在网上搜索后才发布它.
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>
您不能将过滤器应用于普通对象,only to arrays.
$scope.templatesAry = function () { var ary = []; angular.forEach($scope.templates,function (val,key) { ary.push({key: key,val: val}); }); return ary; };
然后筛选:
<li ng-repeat="prop in templatesAry() | orderBy:'-key'"> {{prop.key}}: {{prop.val}} </li>