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

Commit 2240114

Browse files
crisbetokara
authored andcommitted
fix(select): don't override initial model value (#10273)
1 parent b2562cf commit 2240114

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/components/select/select.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -889,7 +889,7 @@ function SelectMenuDirective($parse, $mdUtil, $mdConstant, $mdTheming) {
889889
var newVal = self.isMultiple ? values : values[0];
890890
var prevVal = self.ngModel.$modelValue;
891891

892-
if (usingTrackBy ? !angular.equals(prevVal, newVal) : prevVal !== newVal) {
892+
if (usingTrackBy ? !angular.equals(prevVal, newVal) : (prevVal + '') !== newVal) {
893893
self.ngModel.$setViewValue(newVal);
894894
self.ngModel.$render();
895895
}

src/components/select/select.spec.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -807,6 +807,18 @@ describe('<md-select>', function() {
807807

808808
expect($rootScope.model).toBe(0);
809809
}));
810+
811+
it('should not override the initial model value', inject(function($rootScope) {
812+
$rootScope.model = 2;
813+
814+
var el = setupSelect('ng-model="$root.model"', ['1', '2', '3']);
815+
var selectedOption = selectedOptions(el)[0];
816+
817+
expect($rootScope.model).toBe(2, 'Expected value not to have been overwritten.');
818+
expect(selectedOption).toBeTruthy('Expected an option to be selected.');
819+
expect(selectedOption.getAttribute('value')).toBe('2',
820+
'Expected the corresponding option to have been selected');
821+
}));
810822
});
811823
});
812824

0 commit comments

Comments
 (0)