guagay_wk
guagay_wk

Reputation: 28030

Change image to be loaded based on switch status

I am using AngularJS material. I would like to load an image based on the switch status. Below is the relevant HTML code.

If sw_status.sw1 == true, load image truePic.jpg. If sw_status.sw1 == false, load image falsePic.jpg.

<div ng-controller="AGCtrl">
    <md-switch ng-model="sw_status.sw1" aria-label="Switch_1" ng-change="onChange(sw_status.sw1)">
        Switch_1: {{ sw_status.sw1 }}
    </md-switch>
</div>
<img src='img/truePic.jpg'>

Upvotes: 1

Views: 82

Answers (1)

zamarrowski
zamarrowski

Reputation: 483

<img ng-src="{{sw_status.sw1 ? 'truePic.jpg' : 'falsePic.jpg'}}">

Upvotes: 4

Related Questions