AngularJS:ng-repeat 和 ng-include 在多维数组上 [英] AngularJS: ng-repeat with ng-include on a multidimensional array
问题描述
我昨天开始使用 AngularJS,我需要关于大型抽象的帮助.
所以,我的 Controller.js 中有一个多维数组:
var appname = angular.module('appname');appname.controller('articleCollectionController', ['$scope', '$sce', function ($scope, $sce) {$scope.news = [{title: 'foobar 突破',文本:'foobar foobar',图像:'<img class="img-responsive img-hover" src="images/foo.jpg">',日期:'2014 年 6 月 17 日',作者:'约翰史密斯',文章类型:链接",neverSettle: '吸引人',类别:'新闻'},{title: 'foobars 可用',text: 'foobee foobar',图像:'<img class="img-responsive img-hover" src="images/bar.jpg">',日期:'2014 年 6 月 17 日',作者:'约翰史密斯',文章类型:链接",neverSettle: '创新',类别:'新闻'},{标题: 'foo foo foo',文字:'foobar foobar!foobar',图像:'<img class="img-responsive img-hover" src="images/foobar.jpg">',日期:'2014 年 6 月 17 日',作者:'爱丽丝罗伯茨',文章类型:'pdf',neverSettle: '合作',类别:'新闻'}];}]);
我在所有项目上运行 $sce.trustAsHtml
并且它们完美地呈现 html.
所以,我想做的是使用 ng-include<调用的模板 articleCollection.htm 在我的页面 news.html 上使用
ng-repeat
/代码>.
news.html:
<div ng-include src="js/views/articleCollection.htm"></div>
articleCollection.htm:
<div class="row"><div class="col-md-1 text-center"><p><span ng-bind-html="x.articleType"></span></p><p><span ng-bind-html="x.neverSettle"></span></p><p><span ng-bind-html="x.date"></span></p>
<div class="col-md-5"><a href="news-article.html"><span ng-bind-html="x.image"></span></a>
<div class="col-md-6"><h3><a href="news-article.html"><span ng-bind-html="x.title"></span></a><p>由<span ng-bind-html="x.author"></span></p><p><span ng-bind-html="x.text"></span></p><a class="btn btn-default" href="news-article.html">阅读更多 <i class="fa fa-angle-right"></i></a>