0

I am trying to display images in a list. The path to the image is stored in an array called imagesUrls.

imagesUrls['dhd.png'] = "./img/brands/dhd.png" imagesUrls['channelislands.png'] = "./img/brands/channelislands.png"

etc...

<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');

I can't find the right syntax for the ng-src in the template, can you help please ?

I also tried this:

ng-src="getImgPath(item.brand)"

with this:

$scope.getImgPath = function(str) {
   return imagesUrls[$filter('nospace')($filter('lowercase')(str))];
}
6
  • What is the value of src when you inspect the element in your browser? Do you have a fiddle that we can play with? Commented Oct 23, 2015 at 14:18
  • When I inspect the value is src="imagesUrls['carroll.png']" Commented Oct 23, 2015 at 14:19
  • Have you tried with src instead of ng-src? Commented Oct 23, 2015 at 14:20
  • with src instead of ng-src, I get the same result in the src when I inspect Commented Oct 23, 2015 at 14:35
  • How is the image array related to the prodata object? By order? Commented Oct 23, 2015 at 15:01

1 Answer 1

1

It works with this:

ng-src="{{getImgPath(item.brand)}}"

and

 $scope.getImgPath = function(str) {
    str = $filter('nospace')($filter('lowercase')(str));
    str = str + ".png";
    return $scope.imagesUrls[str];
  }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.