How to detect clicks on an element inside an ionic element?

Using the ion list and ion element, I cannot detect the touch of an element, such as a button or div.

For example, using ng-click does not work here:

<ion-list> <ion-item ng-repeat="device in devices"> <div ng-click="deviceOption(device.id)"> CLICK HERE</div> </ion-item> </ion-list> 

Instead, I tried to use a button with ion buttons, but I don't need to use it.

Why don't we have a simple ion-button directive to detect clicks inside an ion element?

+6
source share
4 answers

So the problem is with ion-item changing the z-index inner div , and the click cannot spread. You can easily get around it by changing the z-index inner div :

 <ion-content class="padding"> <ion-list> <ion-item > <div style="z-index: 1000;" ng-click="test()"> CLICK HERE</div> </ion-item> </ion-list> </ion-content> 
 angular.module('app', ['ionic']).controller('ctrl', function($scope){ $scope.test = function(){ alert('hello'); }; }) 

See "Playground": http://play.ionic.io/app/6227e101719b

+3
source

Adding the enable-pointer-events class should do this.

 <ion-list> <ion-item ng-repeat="device in devices"> <div class="enable-pointer-events" ng-click="deviceOption(device.id)"> CLICK HERE</div> </ion-item> 

+6
source

I had the same problem

Using "on-tap" instead of "ng-click" solved the problem!

+2
source

The easiest way! Just change the event to "on-tap"

 <ion-list> <ion-item ng-repeat="device in devices"> <div on-tap="deviceOption(device.id)"> CLICK HERE</div> </ion-item> </ion-list> 
0
source

Source: https://habr.com/ru/post/989666/


All Articles