0

I have a radio input and written an ng-click function in it. For ADA when the user navigates through the radio button it gets selected on up and down arrow keypress and the ng-click function gets triggered.

But, in the event I am not getting any keyCode and event.which is always "1" and event.type is "click".

Is there any way I can distinguish between mouse click and keypress in the controller function.

.html file

<input tabindex="0" 
       type="radio" 
       name="radio-btn{{index_value}}" 
       id="amountValue-{{index_value}}" 
       ng-click="getSelectedValue($event, amount.selectedValue)" 
       value="Pay Amount" 
       ng-model="amount.selectedValue">

controller.js

scope.getSelectedValue= function (event, selectedValue) {
    console.log("event", event);
};

I've tried adding a directive and bind "key-down keypress" event to it. Inside the directive, I am getting the correct key code but don't know how to pass the keycode to the controller function.

georgeawg
  • 48,608
  • 13
  • 72
  • 95
Ani
  • 1
  • 1
  • please check this https://stackoverflow.com/questions/13318726/easiest-way-to-pass-an-angularjs-scope-variable-from-directive-to-controller – Jayakumar Thangavel Nov 06 '19 at 08:14
  • With a set of radio buttons, the `value` attributes should be different. Read [AngularJS `` Directive API Reference](https://docs.angularjs.org/api/ng/input/input%5Bradio%5D). – georgeawg Nov 06 '19 at 14:09

1 Answers1

0

check event.which value . it will give you the button code value (example ENTER button is 13) .

scope.getSelectedValue= function (event, selectedValue) {
   var e = e || window.event;
    var button = (typeof e.which != "undefined") ? e.which : e.button;
   console.log("button value is ->"+button);
};