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

Commit c3f92e8

Browse files
committed
fix(ngEventDirs): check scope.$$phase only on $rootScope
1 parent 2ae10f6 commit c3f92e8

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

src/ng/directive/ngEventDirs.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ forEach(
5151
'click dblclick mousedown mouseup mouseover mouseout mousemove mouseenter mouseleave keydown keyup keypress submit focus blur copy cut paste'.split(' '),
5252
function(name) {
5353
var directiveName = directiveNormalize('ng-' + name);
54-
ngEventDirectives[directiveName] = ['$parse', function($parse) {
54+
ngEventDirectives[directiveName] = ['$parse', '$rootScope', function($parse, $rootScope) {
5555
return {
5656
restrict: 'A',
5757
compile: function($element, attr) {
@@ -62,7 +62,7 @@ forEach(
6262
var callback = function() {
6363
fn(scope, {$event:event});
6464
};
65-
if (forceAsyncEvents[eventName] && scope.$$phase) {
65+
if (forceAsyncEvents[eventName] && $rootScope.$$phase) {
6666
scope.$evalAsync(callback);
6767
} else {
6868
scope.$apply(callback);

test/ng/directive/ngEventDirsSpec.js

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,16 @@ describe('event directives', function() {
4444

4545
it('should call the listener asynchronously during $apply',
4646
inject(function($rootScope, $compile) {
47-
element = $compile('<input type="text" ng-focus="focus()">')($rootScope);
48-
$rootScope.focus = jasmine.createSpy('focus');
47+
var scope = $rootScope.$new(true);
48+
element = $compile('<input type="text" ng-focus="focus()">')(scope);
49+
scope.focus = jasmine.createSpy('focus');
4950

50-
$rootScope.$apply(function() {
51+
scope.$apply(function() {
5152
element.triggerHandler('focus');
52-
expect($rootScope.focus).not.toHaveBeenCalled();
53+
expect(scope.focus).not.toHaveBeenCalled();
5354
});
5455

55-
expect($rootScope.focus).toHaveBeenCalledOnce();
56+
expect(scope.focus).toHaveBeenCalledOnce();
5657
}));
5758

5859
it('should call the listener synchronously inside of $apply if outside of $apply',
@@ -74,15 +75,16 @@ describe('event directives', function() {
7475

7576
it('should call the listener asynchronously during $apply',
7677
inject(function($rootScope, $compile) {
77-
element = $compile('<input type="text" ng-blur="blur()">')($rootScope);
78-
$rootScope.blur = jasmine.createSpy('blur');
78+
var scope = $rootScope.$new(true);
79+
element = $compile('<input type="text" ng-blur="blur()">')(scope);
80+
scope.blur = jasmine.createSpy('blur');
7981

80-
$rootScope.$apply(function() {
82+
scope.$apply(function() {
8183
element.triggerHandler('blur');
82-
expect($rootScope.blur).not.toHaveBeenCalled();
84+
expect(scope.blur).not.toHaveBeenCalled();
8385
});
8486

85-
expect($rootScope.blur).toHaveBeenCalledOnce();
87+
expect(scope.blur).toHaveBeenCalledOnce();
8688
}));
8789

8890
it('should call the listener synchronously inside of $apply if outside of $apply',

0 commit comments

Comments
 (0)