我正在尝试在列表中显示图像。图像的路径存储在名为imagesUrls
的数组中。
imagesUrls['dhd.png'] = "./img/brands/dhd.png"
imagesUrls['channelislands.png'] = "./img/brands/channelislands.png"
等...
<ion-item collection-repeat="item in prodataSelect | unique:'brand' | orderBy:'brand'" collection-item-height="75" >
<img class="selectBrandImage" ng-src="imagesUrls['{{item.brand | nospace | lowercase}}.png']" />
<span classs="selectBrandName">{{item.brand}}</span>
</ion-item>
controllers.js:
prodata = sessionService.get('prodata');
$scope.prodataSelect = prodata;
$scope.imagesUrls = sessionService.get('imagesUrls');
我无法在模板中找到ng-src
的正确语法,您能帮忙吗?
我也试过这个:
ng-src="getImgPath(item.brand)"
用这个:
$scope.getImgPath = function(str) {
return imagesUrls[$filter('nospace')($filter('lowercase')(str))];
}
答案 0 :(得分:1)
适用于此:
ng-src="{{getImgPath(item.brand)}}"
和
$scope.getImgPath = function(str) {
str = $filter('nospace')($filter('lowercase')(str));
str = str + ".png";
return $scope.imagesUrls[str];
}