简体   繁体   中英

onclick and ng-click event not working

I am working with Onsen UI (angularjs) + Cordova and I have this problem: I have a button that is not working right now, but this button was working sometime ago. Now I cannot even get click event of the button. Does somebody know what is the problem?

HTML:

<ons-list id="list-actions" style="border-top: none"><ons-list-item style="line-height: 1; padding: 0;">
        <ons-row class="action">
          <ons-col class="bt-pres action-col col {{interaction[0].present}}">
            <div class="action-icon"><ons-icon icon="ion-fireball"></ons-icon></div>
            <div class="action-label">Press</div>
          </ons-col>

Javascript:

  //not working
  $(document).on("click",".bt-pres",function(){
    alert("clicked");

Thanks for all your replies. Looking the code again and over again, my bad was I had twice codes like $(document).on('click', elem, func) and it was in conflict. Then I changed this to use angular ngclick function inside controller. This worked like a charm. Thank you all

First of all alert() is not working in neither ripple nor device (as per my knowledge). If you want to trigger the function i suggest ng-click()

example HTML

<div ng-controller="LoginController">
   <ons-button ng-click="Login()">Login</ons-button>
</div>

JS

.controller('LoginController', function () {
   $scope.Login = function () {
      console.log("triggered");
   }
}

in your case try the bellow code

$(document).on("click","div.action-label",function(){
    console.log("triggered");
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM