How to bind Keyboard events with Angularjs
This article mainly introduces Angularjs how to achieve keyboard event binding, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let Xiaobian take you to understand.
Method 1: ng built-in instruction
Log in
Description: bind a todoSomething method on $scope in the corresponding controller
$scope.todoSomething=function ($event) {if ($event.keyCode==13) {/ / enter login ()}}
Method 2: customize the instruction
Html login
Instruction
MyApp.directive ('ngEnter', function () {return function (scope, element, attrs) {element.bind ("keydown keypress", function (event) {if (event.which = 13) {scope.$apply (function () {scope.$eval (attrs.ngEnter);}); event.preventDefault ();}});};})
Conclusion: both methods can realize the function of enter login, but the recommended instruction has less pollution to $scope.
Thank you for reading this article carefully. I hope the article "how to bind keyboard events in Angularjs" shared by the editor will be helpful to everyone. At the same time, I also hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!