Best way to change images ontap

Hi everyone!

I’ve been looking for a good way to switch between a standard image to an activated one (when I click it)
I googled it, looking for a way to do it using angular but I don’t know if ionic has something to help me with this.

links that I found useful but maybe not good solutions :

Ionic docs are your best friend. Look there before posting a question :smile:. Take a look at this.

So in your view you could have something like:

<img ng-src="{{ imageUrl }} on-tap="onTap()" />

Then in your controller:

$scope.imageUrl = '';

$scope.onTap = function() {
	$scope.imageUrl = '';


Thanks @seanhill

I’ve done something similar to this (but I didn’t use onTap method, so thank you :smile:)

But I rewrote the code using the “activated” class


    &.divulga {
      background-image: url("../img/task/divulga-causa.png");
        background-image: url("../img/task/divulga-causa-activated.png");

So every time I click on the ‘a’ element the activated class is called and the images are updated

I don’t know which one is the best solution, but I chose the second approach because It seemed to be more “clean”.

Again thanks for the help =)

No problem :slight_smile: Yeah either solution would work, just depends on your needs!