This repository was archived by the owner on Apr 12, 2024. It is now read-only.
File tree 2 files changed +62
-1
lines changed
2 files changed +62
-1
lines changed Original file line number Diff line number Diff line change 37
37
*/
38
38
var ngEventDirectives = { } ;
39
39
forEach (
40
- 'click dblclick mousedown mouseup mouseover mouseout mousemove mouseenter mouseleave' . split ( ' ' ) ,
40
+ 'click dblclick mousedown mouseup mouseover mouseout mousemove mouseenter mouseleave keydown keyup ' . split ( ' ' ) ,
41
41
function ( name ) {
42
42
var directiveName = directiveNormalize ( 'ng-' + name ) ;
43
43
ngEventDirectives [ directiveName ] = [ '$parse' , function ( $parse ) {
@@ -164,6 +164,38 @@ forEach(
164
164
*/
165
165
166
166
167
+ /**
168
+ * @ngdoc directive
169
+ * @name ng.directive:ngKeydown
170
+ *
171
+ * @description
172
+ * Specify custom behavior on keydown event.
173
+ *
174
+ * @element ANY
175
+ * @param {expression } ngKeydown {@link guide/expression Expression } to evaluate upon
176
+ * keydown. (Event object is available as `$event` and can be interrogated for keyCode, altKey, etc.)
177
+ *
178
+ * @example
179
+ * See {@link ng.directive:ngClick ngClick}
180
+ */
181
+
182
+
183
+ /**
184
+ * @ngdoc directive
185
+ * @name ng.directive:ngKeyup
186
+ *
187
+ * @description
188
+ * Specify custom behavior on keyup event.
189
+ *
190
+ * @element ANY
191
+ * @param {expression } ngKeyup {@link guide/expression Expression } to evaluate upon
192
+ * keyup. (Event object is available as `$event` and can be interrogated for keyCode, altKey, etc.)
193
+ *
194
+ * @example
195
+ * See {@link ng.directive:ngClick ngClick}
196
+ */
197
+
198
+
167
199
/**
168
200
* @ngdoc directive
169
201
* @name ng.directive:ngSubmit
Original file line number Diff line number Diff line change
1
+ 'use strict' ;
2
+
3
+ describe ( 'ngKeyup and ngKeydown directives' , function ( ) {
4
+ var element ;
5
+
6
+ afterEach ( function ( ) {
7
+ dealoc ( element ) ;
8
+ } ) ;
9
+
10
+ it ( 'should get called on a keyup' , inject ( function ( $rootScope , $compile ) {
11
+ element = $compile ( '<input ng-keyup="touched = true">' ) ( $rootScope ) ;
12
+ $rootScope . $digest ( ) ;
13
+ expect ( $rootScope . touched ) . toBeFalsy ( ) ;
14
+
15
+ browserTrigger ( element , 'keyup' ) ;
16
+ expect ( $rootScope . touched ) . toEqual ( true ) ;
17
+ } ) ) ;
18
+
19
+ it ( 'should get called on a keydown' , inject ( function ( $rootScope , $compile ) {
20
+ element = $compile ( '<input ng-keydown="touched = true">' ) ( $rootScope ) ;
21
+ $rootScope . $digest ( ) ;
22
+ expect ( $rootScope . touched ) . toBeFalsy ( ) ;
23
+
24
+ browserTrigger ( element , 'keydown' ) ;
25
+ expect ( $rootScope . touched ) . toEqual ( true ) ;
26
+ } ) ) ;
27
+
28
+ } ) ;
29
+
You can’t perform that action at this time.
0 commit comments