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

Commit

Permalink
fix(select): multiple select clears on undefined ngModel
Browse files Browse the repository at this point in the history
closes #2921
  • Loading branch information
rschmukler committed Aug 14, 2015
1 parent cca1955 commit 346198a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/components/select/select.js
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,7 @@ function SelectMenuDirective($parse, $mdUtil, $mdTheming) {
};

function renderMultiple() {
var newSelectedValues = self.ngModel.$modelValue || self.ngModel.$viewValue;
var newSelectedValues = self.ngModel.$modelValue || self.ngModel.$viewValue || [];
if (!angular.isArray(newSelectedValues)) return;

var oldSelected = Object.keys(self.selected);
Expand Down
9 changes: 9 additions & 0 deletions src/components/select/select.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,15 @@ describe('<md-select>', function() {
expect($rootScope.model).toEqual([]);
}));

it('renders nothing if undefined is set', inject(function($rootScope) {
$rootScope.model = [1, 2];
var el = setupMultiple('ng-model="$root.model"', [1,2,3,4]);
expect(selectedOptions(el).length).toBe(2);
$rootScope.$apply('model = undefined');
$rootScope.$digest();
expect(selectedOptions(el).length).toBe(0);
}));

it('adding a valid value to the model selects its option', inject(function($rootScope) {
$rootScope.model = [];
var el = setupMultiple('ng-model="$root.model"', [1,2,3,4]);
Expand Down

0 comments on commit 346198a

Please sign in to comment.