Ionic-framework: No click event on icon

Created on 21 May 2014  路  18Comments  路  Source: ionic-team/ionic-framework

If I add only icon it doesn't recieve click events on android 4.1:
<i class="ion-help-circled" ng-click="alert('none');"></i>
or
<a ng-click="alert('none');"><i class="ion-help-circled"></i></a>

This recieves event on text only:
<a ng-click="alert('none');"><i class="ion-help-circled"></i> Text</a>

reply

Most helpful comment

I was able to get this working wrapping the icon with a and the on-tap zhuhu mentioned earlier:

<span on-tap="clearSearch()"><i class="icon ion-close"></i></span>

All 18 comments

Try:

<a class="button button-clear" ng-click="something()">
  <i class="icon ion-help-circled"></i>
</a>

That works but makes padding that I don't want to

piernik, were you able to remove the padding?

I've iggnored icon and set text as well <a ng-click="alert('none');">Get help <i class="ion-help-circled"></i></a> so problem is not solved, but I do know how to get rid of padding ;)

I believe this is because the actual image is a pseudo element. @adamdbradley would our click modifications fire on a pseudo element?

@piernik, could you put together a quick codepen for us to test against?

Looks like its a quirky Android 4.1 thing. I was able to replicate it on 4.1, but not 4.2. In your case, since you do not want to use a button and override the padding, you can instead add a background color and then the whole element is clickable. Thanks

The only thing that worked for me was to was to change the event to ng-mouseover. Works fine on mobile devices, does not work in a browser (ionic 1.2.5; Chrome 32 on Ubuntu 14.04).

How about using "on-tap"?

I can confirm this while testing in Chrome. Even when wrapping with other elements, the parent elements will not fire.

I'm having this issue as well. Are you guys doing an e.preventDefault() on <i> targets?
Tested on beta 14 nigthly 995

Update: I have it working replacing the parent <label> with a <div>

As @mhartington explains here: http://forum.ionicframework.com/t/cannot-tap-click-a-clear-search-icon-inside-an-input-label/4237/7

Thing to remember about how ionic deals with setting focus to inputs:

We use labels to to watch for any tap events, then check to see if that label has an input inside of it. If so, set focus to the input.

To use a button along the input, swap the label to a span or div, your ng-clicks will work fine after that.

I was able to get this working wrapping the icon with a and the on-tap zhuhu mentioned earlier:

<span on-tap="clearSearch()"><i class="icon ion-close"></i></span>

I'd like to put a big green checkmark next to the comment from FdezRomero. Thanks!

Got same issue today. Changing event handler to 'on-tap' worked.

'on-tap' works. Kudos

on-tap did not work for me. Had to use ng-click for it to work on Android 4.1.2.

<a ng-click="substract()"><i class="icon ion-ios-minus"></i></a>

@FdezRomero Changing the label element to a div fixed it for me. ty

Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Ionic, please create a new issue and ensure the template is fully filled out.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

vswarte picture vswarte  路  3Comments

RobFerguson picture RobFerguson  路  3Comments

BilelKrichen picture BilelKrichen  路  3Comments

manucorporat picture manucorporat  路  3Comments

GeorgeAnanthSoosai picture GeorgeAnanthSoosai  路  3Comments