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

Commit bf59d72

Browse files
shahatatbosch
authored andcommitted
fix(input): check scope.$$phase only on $rootScope
1 parent 995a8d3 commit bf59d72

File tree

2 files changed

+22
-11
lines changed

2 files changed

+22
-11
lines changed

src/ng/directive/input.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -958,7 +958,7 @@ function baseInputType(scope, element, attr, ctrl, $sniffer, $browser) {
958958
// a row.
959959
var revalidate = validity && ctrl.$$hasNativeValidators;
960960
if (ctrl.$viewValue !== value || (value === '' && revalidate)) {
961-
if (scope.$$phase) {
961+
if (scope.$root.$$phase) {
962962
ctrl.$setViewValue(value, event, revalidate);
963963
} else {
964964
scope.$apply(function() {

test/ng/directive/inputSpec.js

+21-10
Original file line numberDiff line numberDiff line change
@@ -1152,19 +1152,30 @@ describe('input', function() {
11521152
});
11531153

11541154
if (!_jqLiteMode) {
1155-
it('should not cause the double $digest when triggering an event using jQuery', function() {
1156-
$sniffer.hasEvent = function(eventName) {
1157-
return eventName !== 'input';
1158-
};
1155+
describe('double $digest when triggering an event using jQuery', function() {
1156+
function run() {
1157+
$sniffer.hasEvent = function(eventName) {
1158+
return eventName !== 'input';
1159+
};
1160+
1161+
compileInput('<input type="text" ng-model="name" name="alias" ng-change="change()" />');
1162+
1163+
scope.field = 'fake field';
1164+
scope.$watch('field', function() {
1165+
// We need to use _originalTrigger since trigger is modified by Angular Scenario.
1166+
inputElm._originalTrigger('change');
1167+
});
1168+
scope.$apply();
1169+
}
11591170

1160-
compileInput('<input type="text" ng-model="name" name="alias" ng-change="change()" />');
1171+
it('should not cause the double $digest with non isolate scopes', function() {
1172+
run();
1173+
});
11611174

1162-
scope.field = 'fake field';
1163-
scope.$watch('field', function() {
1164-
// We need to use _originalTrigger since trigger is modified by Angular Scenario.
1165-
inputElm._originalTrigger('change');
1175+
it('should not cause the double $digest with isolate scopes', function() {
1176+
scope = scope.$new(true);
1177+
run();
11661178
});
1167-
scope.$apply();
11681179
});
11691180
}
11701181
});

0 commit comments

Comments
 (0)