Page 1 of 1

how to reference an element in ionic app from an ng-click event

Posted: Tue Dec 26, 2017 6:16 pm
by Frank7390035

Hello,

Apologies for the naive question: I have a list of items and I would like to change the class of a particular list-item when the user taps on this item using some js via ng-click

I thought I could reference the selected element using the keyword "this" e.g.

this.removeClass("myclass").

This doesn't work..what should I do instead?

Thanks,
Frank


how to reference an element in ionic app from an ng-click event

Posted: Fri Dec 29, 2017 10:27 am
by Serhii Kulibaba

Hello Frank,

You can't reference an element in the function ng-click. Please add the class to that component using the scope variable and directive ng-class: https://docs.angularjs.org/api/ng/dir...

  1. Set the value of the scope variable in the function ng-click
  2. Use that variable in the directive ng-click