File tree 2 files changed +41
-3
lines changed
2 files changed +41
-3
lines changed Original file line number Diff line number Diff line change 31
31
</example>
32
32
*/
33
33
/*
34
- * A directive that allows creation of custom onclick handlers that are defined as angular
34
+ * A directive that allows creation of custom event handlers that are defined as angular
35
35
* expressions and are compiled and executed within the current scope.
36
36
*
37
37
* Events that are handled via these handler are always configured not to propagate further.
@@ -47,9 +47,13 @@ forEach(
47
47
var fn = $parse ( attr [ directiveName ] ) ;
48
48
return function ngEventHandler ( scope , element ) {
49
49
element . on ( lowercase ( name ) , function ( event ) {
50
- scope . $apply ( function ( ) {
50
+ if ( scope . $$phase ) {
51
51
fn ( scope , { $event :event } ) ;
52
- } ) ;
52
+ } else {
53
+ scope . $apply ( function ( ) {
54
+ fn ( scope , { $event :event } ) ;
55
+ } ) ;
56
+ }
53
57
} ) ;
54
58
} ;
55
59
}
Original file line number Diff line number Diff line change @@ -39,4 +39,38 @@ describe('event directives', function() {
39
39
expect ( $rootScope . formSubmitted ) . toEqual ( 'foo' ) ;
40
40
} ) ) ;
41
41
} ) ;
42
+
43
+ describe ( 'ngBlur' , function ( ) {
44
+ it ( 'should get called when ngKeydown triggers blur' , inject ( function ( $rootScope , $compile ) {
45
+ $rootScope . blur = function ( ) {
46
+ browserTrigger ( element , 'blur' ) ;
47
+ } ;
48
+
49
+ element = $compile ( '<input type="text" ng-blur="blurred = true" ng-keydown="blur()" />' ) ( $rootScope ) ;
50
+
51
+ $rootScope . $digest ( ) ;
52
+ expect ( $rootScope . blurred ) . not . toBeDefined ( ) ;
53
+
54
+ browserTrigger ( element , 'keydown' ) ;
55
+ expect ( $rootScope . blurred ) . toEqual ( true ) ;
56
+ } ) ) ;
57
+ } ) ;
58
+
59
+ describe ( 'ngFocus' , function ( ) {
60
+ it ( 'should get called when ngClick triggers focus' , inject ( function ( $rootScope , $compile ) {
61
+ $rootScope . focus = function ( ) {
62
+ browserTrigger ( element . children ( ) [ 0 ] , 'focus' ) ;
63
+ } ;
64
+
65
+ element = $compile ( '<div><input type="text" ng-focus="focused = true" />' +
66
+ '<button type="button" ng-click="focus()"></button></div>' ) ( $rootScope ) ;
67
+
68
+ $rootScope . $digest ( ) ;
69
+ expect ( $rootScope . focused ) . not . toBeDefined ( ) ;
70
+
71
+ browserTrigger ( element . children ( ) [ 1 ] , 'click' ) ;
72
+ expect ( $rootScope . focused ) . toEqual ( true ) ;
73
+ } ) ) ;
74
+ } ) ;
75
+
42
76
} ) ;
You can’t perform that action at this time.
0 commit comments