Below is my controller scope function :
MyApp.controller("MyController", function ($scope, MyService) {
$scope.hposition = "";
$scope.selectedRow = 0;
$scope.pSearch = {};
$scope.selectH = function (index, hId, myModel) {
$scope.selectedRow = index;
var resultList = MyService.selectH(hId, $scope.hposition, myModel);
resultList.then(function (response) {
$scope.myModel= response.data;
$("#divlookup").dialog('close');
})
} });
And I have a directive for keyboard events - keydown, keyup and keypress.
MyApp.directive('arrowSelector', ['$document', function ($document) {
return {
restrict: 'A',
link: function (scope, elem, attrs, ctrl) {
$document.bind('keydown', function (e) {
//if (elemFocus) {
if (e.keyCode == 38 || e.keyCode == 37) {
console.log(scope.selectedRow);
if (scope.selectedRow == 0) {
return;
}
scope.selectedRow--;
scope.$apply();
e.preventDefault();
}
if (e.keyCode == 40 || e.keyCode == 39) {
if (scope.selectedRow == scope.hlist.length - 1) {
return;
}
scope.selectedRow++;
scope.$apply();
e.preventDefault();
}
if (e.keyCode == 13) {
var resultList = scope.selectH(hId, $scope.hposition, myModel);
resultList.then(function (response) {
$scope.myModel= response.data;
$("#divlookup").dialog('close');
});
scope.$apply();
e.preventDefault();
}
});
}
};}]);
I tried calling the function scope.selectH(), but it is not working. How can I call my selectH function when e.keyCode==13? Is there any other better way to do keyboard up and down arrow events ?