For using a keypress event in AngularJS you need to add a directive, as follows:-
See the Javascript code below:-
app.directive('myEnter', function () {
return function (scope, element, attrs) {
element.bind("keydown keypress", function (event) {
if(event.which === 13) {
scope.$apply(function (){
scope.$eval(attrs.myEnter);
});
event.preventDefault();
}
});
};
});
Looking for Angularjs material from basics! Refer to this video on Angularjs provided by Intellipaat:
HTML Code:
<div ng-app="" ng-controller="MainCtrl">
<input type="text" my-enter="doSomething()">
</div>