Get the App
SLTechnology News&Howtos  ›  Development  › 

How to bind Keyboard events with Angularjs

Shulou Source: shulou.com Published: 2022-06-03 20:07:02 11月12日 Update

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!

Tags: Instructions methods articles logins events keyboards values interests functions at the same time controllers methods more friends knowledge editing industry information information channels channels Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Redmi Linux OPPO Reno Shulou Tech Info Shulou Information