angular-keycode

A code service of keyboard events.

Homepage

Module License: MIT

Added by: Sam Deering

GitHub

Repository

jullierme/angular-keycode

Stats

Stars: 9

Watchers: 9

Forks: 3

Module Description

Bower Join the chat at https://gitter.im/jullierme/angular-keycode

No More Magic Numbers \o/

A code service of keyboard events

Less than 2 kb minified

Installation

bower

# To install latest release
bower install angular-keycode


# To install latest release and update bower.json
bower install angular-keycode --save

Please note that Angular KeyCode requires Angular 1.2.x or higher.

Registrer

angular.module('myApp',['angular-keycode']);

Import

<script src="bower_components/angular-keycode/angular-keycode.min.js"></script>

Using

(function(){
    'use strict';

    MyService.$inject = ['KeyCode'];

    function MyService(KeyCode){
        var vm = this;
        vm.onKeydown = onKeydown;

        //wrong
        function onKeydown($event){
            var code = $event.which || $event.keyCode;

            if(code === 13){//magic number detected
                ...do
            }
        }

        //correct
        function onKeydown($event){
            var code = $event.which || $event.keyCode;

            if(code === KeyCode.ENTER){
                ...do
            }
        }

    }
})();

Examples

KeyCode.BACKSPACE
KeyCode.TAB
KeyCode.ENTER

KeyCode.A
KeyCode.B
KeyCode.C

KeyCode.NUMPAD_8
KeyCode.NUMPAD_9

KeyCode.F1
KeyCode.F2
KeyCode.F3

MORE...

LICENCE

MIT

Module stats last updated: 2016-10-29 03:18:40

Disclaimer: Some data on this page may have been gathered from the authors GitHub respository. If you see any mistakes or outdated information please let us know. Thanks!