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

Commit 346198a

Browse files
committed
fix(select): multiple select clears on undefined ngModel
closes #2921
1 parent cca1955 commit 346198a

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

src/components/select/select.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -610,7 +610,7 @@ function SelectMenuDirective($parse, $mdUtil, $mdTheming) {
610610
};
611611

612612
function renderMultiple() {
613-
var newSelectedValues = self.ngModel.$modelValue || self.ngModel.$viewValue;
613+
var newSelectedValues = self.ngModel.$modelValue || self.ngModel.$viewValue || [];
614614
if (!angular.isArray(newSelectedValues)) return;
615615

616616
var oldSelected = Object.keys(self.selected);

src/components/select/select.spec.js

+9
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,15 @@ describe('<md-select>', function() {
463463
expect($rootScope.model).toEqual([]);
464464
}));
465465

466+
it('renders nothing if undefined is set', inject(function($rootScope) {
467+
$rootScope.model = [1, 2];
468+
var el = setupMultiple('ng-model="$root.model"', [1,2,3,4]);
469+
expect(selectedOptions(el).length).toBe(2);
470+
$rootScope.$apply('model = undefined');
471+
$rootScope.$digest();
472+
expect(selectedOptions(el).length).toBe(0);
473+
}));
474+
466475
it('adding a valid value to the model selects its option', inject(function($rootScope) {
467476
$rootScope.model = [];
468477
var el = setupMultiple('ng-model="$root.model"', [1,2,3,4]);

0 commit comments

Comments
 (0)