AngularJS displays svg file on page

I have an angularJS function that reads data from a json file and returns me an object with multiple SVG image file names.

I have ng-repeat on the return object to view and display all SVG files on the page.

Here is my ng-repeat on my template

<div ng-repeat="items in libCtrl.categories track by $index">
  <div ng-include="img/library/items.categoryImage"></div>
</div>

This code does not display the SVG image file on the page. But if I hardcode the value of the file names in ng-include, it works.

<div ng-repeat="items in libCtrl.categories track by $index">
  <div ng-include="'img/library/myfile.svg'"></div>
</div>

How can I make it work using the data from my items.categoryImage?

+4
source share
1 answer

Check out a working demo: Plunker .

Use <div ng-include="'img/library/' + items.categoryImage"></div>

+4
source

Source: https://habr.com/ru/post/1607943/


All Articles