更新:
在我的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>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。