我使用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