Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

feat(directive): ng:keypress New directives for binding to keypress eve... #2101

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion src/ng/directive/ngEventDirs.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
*/
var ngEventDirectives = {};
forEach(
'click dblclick mousedown mouseup mouseover mouseout mousemove mouseenter mouseleave keydown keyup'.split(' '),
'click dblclick mousedown mouseup mouseover mouseout mousemove mouseenter mouseleave keydown keyup keypress'.split(' '),
function(name) {
var directiveName = directiveNormalize('ng-' + name);
ngEventDirectives[directiveName] = ['$parse', function($parse) {
Expand Down Expand Up @@ -196,6 +196,22 @@ forEach(
*/


/**
* @ngdoc directive
* @name ng.directive:ngKeypress
*
* @description
* Specify custom behavior on keypress event.
*
* @element ANY
* @param {expression} ngKeypress {@link guide/expression Expression} to evaluate upon
* keypress. (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:ngSubmit
Expand Down
9 changes: 9 additions & 0 deletions test/ng/directive/ngKeySpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,14 @@ describe('ngKeyup and ngKeydown directives', function() {
expect($rootScope.touched).toEqual(true);
}));

it('should get called on a keypress', inject(function($rootScope, $compile) {
element = $compile('<input ng-keypress="touched = true">')($rootScope);
$rootScope.$digest();
expect($rootScope.touched).toBeFalsy();

browserTrigger(element, 'keypress');
expect($rootScope.touched).toEqual(true);
}));

});