javascript - Can't call angular ng-click from jQuery -


im trying call ng-click jquery cant work. can tell me how properly?

html:

<a ng-click="changedata()">testing</a> <a ng-click="changedata()">testing 2</a> <a ng-click="changedata()">testing 3</a> 

jquery:

$(document).keydown(function(e){     if (checknav && checknav()) return;     if (e.keycode == 37) {         // left         setcurrent(x,y-1);         e.preventdefault();     } else if (e.keycode == 38) {         //         setcurrent(x-1,y);         e.preventdefault();     } else if (e.keycode == 39) {         // right         setcurrent(x,y+1);         e.preventdefault();     } else if (e.keycode == 40) {         // down         setcurrent(x+1,y);         e.preventdefault();     } else if (e.keycode == 13) {          $('a[ng-click="changedata()"]')      } }); 

i want call same function ng-click when clicking enter. works fine if have following code hrefs when clicking enter:

} else if (e.keycode == 13) {                 window.location = current.attr('href');                 e.preventdefault();             } 

thanks!

i think mean want this. let me know if intent or not:

index.html

<input ng-keyup="keyfn(event=$event)" ngclick="clickfn()">click</input> 

controller.js

angular.module('myapp')     .controller('myctrl', function($scope) {          $scope.keyfn = function(event){           if (event.keycode && event.keycode === 13/*enter key*/){               somefunction();           }         };         $scope.clickfn = function(){             somefunction();         }     });  function somefunction(){     console.log("event fired");     //functionality shared between click , `enter` keypress } 

Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -