kayasa kayasa - 1 year ago 105
AngularJS Question

Ionic - ng-src load icons based on conditions

In my ionic app, I need to load icons using ng-src. Depending on the format of the document, corresponding icon needs to be displayed.

I was trying to do something like

<img ng-src="{{format === 'docx' ? '../img/Word-icon.png' : '../img/PDF-icon.png')}}">

If the format is docx (I have verified that format value is coming correctly), then display Word-icon.png. For everything else display PDF-icon.png.

This is not working. In fact the page stops loading when I do this. It does not throw an error in the browser console but also does not load the page. Icons are stored in the img directory inside the www folder in the ionic app.

Answer Source

You had unnecessary ) at the end of expression.

<img ng-src="{{format === 'docx' ? '../img/Word-icon.png' : '../img/PDF-icon.png'}}">
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download