diff --git a/src/ng/directive/ngOptions.js b/src/ng/directive/ngOptions.js index 6364f0cf6d55..2498042579d6 100644 --- a/src/ng/directive/ngOptions.js +++ b/src/ng/directive/ngOptions.js @@ -706,8 +706,7 @@ var ngOptionsDirective = ['$compile', '$parse', function($compile, $parse) { // Check to see if the value has changed due to the update to the options if (!ngModelCtrl.$isEmpty(previousValue)) { var nextValue = selectCtrl.readValue(); - if (ngOptions.trackBy && !equals(previousValue, nextValue) || - previousValue !== nextValue) { + if (ngOptions.trackBy ? !equals(previousValue, nextValue) : previousValue !== nextValue) { ngModelCtrl.$setViewValue(nextValue); ngModelCtrl.$render(); } diff --git a/test/ng/directive/ngOptionsSpec.js b/test/ng/directive/ngOptionsSpec.js index 399d64392175..33cdfb00ce38 100644 --- a/test/ng/directive/ngOptionsSpec.js +++ b/test/ng/directive/ngOptionsSpec.js @@ -1176,6 +1176,26 @@ describe('ngOptions', function() { }); + it('should not set view value again if the tracked property of the model has not changed when using trackBy', function() { + + createSelect({ + 'ng-model': 'selected', + 'ng-options': 'item for item in arr track by item.id' + }); + + scope.$apply(function() { + scope.selected = {id: 10, label: 'ten'}; + }); + + spyOn(element.controller('ngModel'), '$setViewValue'); + + scope.$apply(function() { + scope.arr[0] = {id: 10, label: 'ten'}; + }); + + expect(element.controller('ngModel').$setViewValue).not.toHaveBeenCalled(); + }); + it('should not re-render if a property of the model is changed when not using trackBy', function() { createSelect({