mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-05-11 00:03:10 +00:00
feat(directive): ng:keydown, ng:keyup
New directives for binding to keydown and keyup events. Closes #1035
This commit is contained in:
parent
f2d526190a
commit
e03182f018
2 changed files with 62 additions and 1 deletions
|
|
@ -37,7 +37,7 @@
|
||||||
*/
|
*/
|
||||||
var ngEventDirectives = {};
|
var ngEventDirectives = {};
|
||||||
forEach(
|
forEach(
|
||||||
'click dblclick mousedown mouseup mouseover mouseout mousemove mouseenter mouseleave'.split(' '),
|
'click dblclick mousedown mouseup mouseover mouseout mousemove mouseenter mouseleave keydown keyup'.split(' '),
|
||||||
function(name) {
|
function(name) {
|
||||||
var directiveName = directiveNormalize('ng-' + name);
|
var directiveName = directiveNormalize('ng-' + name);
|
||||||
ngEventDirectives[directiveName] = ['$parse', function($parse) {
|
ngEventDirectives[directiveName] = ['$parse', function($parse) {
|
||||||
|
|
@ -164,6 +164,38 @@ forEach(
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ngdoc directive
|
||||||
|
* @name ng.directive:ngKeydown
|
||||||
|
*
|
||||||
|
* @description
|
||||||
|
* Specify custom behavior on keydown event.
|
||||||
|
*
|
||||||
|
* @element ANY
|
||||||
|
* @param {expression} ngKeydown {@link guide/expression Expression} to evaluate upon
|
||||||
|
* keydown. (Event object is available as `$event` and can be interrogated for keyCode, altKey, etc.)
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* See {@link ng.directive:ngClick ngClick}
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ngdoc directive
|
||||||
|
* @name ng.directive:ngKeyup
|
||||||
|
*
|
||||||
|
* @description
|
||||||
|
* Specify custom behavior on keyup event.
|
||||||
|
*
|
||||||
|
* @element ANY
|
||||||
|
* @param {expression} ngKeyup {@link guide/expression Expression} to evaluate upon
|
||||||
|
* keyup. (Event object is available as `$event` and can be interrogated for keyCode, altKey, etc.)
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* See {@link ng.directive:ngClick ngClick}
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ngdoc directive
|
* @ngdoc directive
|
||||||
* @name ng.directive:ngSubmit
|
* @name ng.directive:ngSubmit
|
||||||
|
|
|
||||||
29
test/ng/directive/ngKeySpec.js
Normal file
29
test/ng/directive/ngKeySpec.js
Normal file
|
|
@ -0,0 +1,29 @@
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
describe('ngKeyup and ngKeydown directives', function() {
|
||||||
|
var element;
|
||||||
|
|
||||||
|
afterEach(function() {
|
||||||
|
dealoc(element);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should get called on a keyup', inject(function($rootScope, $compile) {
|
||||||
|
element = $compile('<input ng-keyup="touched = true">')($rootScope);
|
||||||
|
$rootScope.$digest();
|
||||||
|
expect($rootScope.touched).toBeFalsy();
|
||||||
|
|
||||||
|
browserTrigger(element, 'keyup');
|
||||||
|
expect($rootScope.touched).toEqual(true);
|
||||||
|
}));
|
||||||
|
|
||||||
|
it('should get called on a keydown', inject(function($rootScope, $compile) {
|
||||||
|
element = $compile('<input ng-keydown="touched = true">')($rootScope);
|
||||||
|
$rootScope.$digest();
|
||||||
|
expect($rootScope.touched).toBeFalsy();
|
||||||
|
|
||||||
|
browserTrigger(element, 'keydown');
|
||||||
|
expect($rootScope.touched).toEqual(true);
|
||||||
|
}));
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
Loading…
Reference in a new issue