我使用ng-repeat来绑定来自指令的图像(与我们通常制作星星评分相同)。在我的情况下,我有图像,其中一些应该有标题,而不是全部。有没有办法制定一个条件,只会显示第二张和最后一张图片的标题?没有对所有图像Angular ng-repeat images with caption only for 2 of the
我的HTML创建一个数组:
<ul class="qty">
<li ng-repeat="image in imagesArray">
<img ng-model="imgUrl" ng-src="{{imgUrl}}">
<div>caption</div>
</li>
我的应用程序:
var myDirectives = (function() {
var myDirectives = angular.module('myDirectives', []);
myDirectives.directive('myImages', function() {
return {
restrict: 'A',
scope: {
qty: '='
},
link: function ($scope) {
$scope.imgUrl = "http://farm6.staticflickr.com/5579/14671096893_806ec359b7_m.jpg";
$scope.imagesArray = [];
for (var i = 0; i < $scope.qty; i++) {
$scope.imagesArray.push({});
}
},
templateUrl: function() { return 'stars.html' },
}
});
return myDirectives; }());
Plunkr: http://plnkr.co/edit/IdXaRDB9INZlZbWSTmam?p=preview
我明白了!我只是错过了研究ng-repeat的属性。现在更清楚了。将与它一起玩。谢谢! – Natalya