You can create a controller and install it on the body tag, as well as set a key event callback:
<body ng-controller="keycontroller" ui-keyup="{'enter':'callback($event)'}" > <input type="text" ng-model="test1" /> <input type="text" ng-model="test2" /> </body>
And then install:
function keycontroller($scope) { $scope.test1= "It should work here..."; $scope.test2= "...and also here."; $scope.callback = function fn($event) { console.log("Enter key pressed"); }; } var app = angular.module("app", ['ui.keypress']); app.controller("keycontroller", keycontroller);
source share