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

Commit 203ea10

Browse files
shahatatbosch
authored andcommitted
fix(ngEventDirs): check scope.$$phase only on $rootScope
Closes #8891, #8849
1 parent bf59d72 commit 203ea10

File tree

2 files changed

+46
-22
lines changed

2 files changed

+46
-22
lines changed

src/ng/directive/ngEventDirs.js

+2-2
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

+44-20
Original file line numberDiff line numberDiff line change
@@ -42,18 +42,30 @@ describe('event directives', function() {
4242

4343
describe('focus', function() {
4444

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

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

55-
expect($rootScope.focus).toHaveBeenCalledOnce();
56-
}));
56+
expect(scope.focus).toHaveBeenCalledOnce();
57+
});
58+
}
59+
60+
it('should call the listener with non isolate scopes', inject(function($rootScope) {
61+
run($rootScope.$new());
62+
}));
63+
64+
it('should call the listener with isolate scopes', inject(function($rootScope) {
65+
run($rootScope.$new(true));
66+
}));
67+
68+
});
5769

5870
it('should call the listener synchronously inside of $apply if outside of $apply',
5971
inject(function($rootScope, $compile) {
@@ -72,18 +84,30 @@ describe('event directives', function() {
7284

7385
describe('blur', function() {
7486

75-
it('should call the listener asynchronously during $apply',
76-
inject(function($rootScope, $compile) {
77-
element = $compile('<input type="text" ng-blur="blur()">')($rootScope);
78-
$rootScope.blur = jasmine.createSpy('blur');
87+
describe('call the listener asynchronously during $apply', function() {
88+
function run(scope) {
89+
inject(function($compile) {
90+
element = $compile('<input type="text" ng-blur="blur()">')(scope);
91+
scope.blur = jasmine.createSpy('blur');
7992

80-
$rootScope.$apply(function() {
81-
element.triggerHandler('blur');
82-
expect($rootScope.blur).not.toHaveBeenCalled();
83-
});
93+
scope.$apply(function() {
94+
element.triggerHandler('blur');
95+
expect(scope.blur).not.toHaveBeenCalled();
96+
});
8497

85-
expect($rootScope.blur).toHaveBeenCalledOnce();
86-
}));
98+
expect(scope.blur).toHaveBeenCalledOnce();
99+
});
100+
}
101+
102+
it('should call the listener with non isolate scopes', inject(function($rootScope) {
103+
run($rootScope.$new());
104+
}));
105+
106+
it('should call the listener with isolate scopes', inject(function($rootScope) {
107+
run($rootScope.$new(true));
108+
}));
109+
110+
});
87111

88112
it('should call the listener synchronously inside of $apply if outside of $apply',
89113
inject(function($rootScope, $compile) {

0 commit comments

Comments
 (0)