diff --git a/src/uiSelectMultipleDirective.js b/src/uiSelectMultipleDirective.js index 75744a77e..59e911422 100644 --- a/src/uiSelectMultipleDirective.js +++ b/src/uiSelectMultipleDirective.js @@ -156,7 +156,7 @@ uis.directive('uiSelectMultiple', ['uiSelectMinErr','$timeout', function(uiSelec if(!angular.isArray(ngModel.$viewValue)){ // Have tolerance for null or undefined values if(angular.isUndefined(ngModel.$viewValue) || ngModel.$viewValue === null){ - $select.selected = []; + ngModel.$viewValue = []; } else { throw uiSelectMinErr('multiarr', "Expected model value to be array but got '{0}'", ngModel.$viewValue); } diff --git a/test/select.spec.js b/test/select.spec.js index 063b9fb66..3bd55f9c3 100644 --- a/test/select.spec.js +++ b/test/select.spec.js @@ -2161,6 +2161,44 @@ describe('ui-select tests', function() { expect(el.scope().$select.multiple).toBe(true); }); + it('should have tolerance for undefined values', function () { + + scope.modelValue = undefined; + + var el = compileTemplate( + ' \ + {{$item.name}} <{{$item.email}}> \ + \ +
\ +
\ +
\ +
\ + ' + ); + + expect($(el).scope().$select.selected).toEqual([]); + + }); + + it('should have tolerance for null values', function () { + + scope.modelValue = null; + + var el = compileTemplate( + ' \ + {{$item.name}} <{{$item.email}}> \ + \ +
\ +
\ +
\ +
\ + ' + ); + + expect($(el).scope().$select.selected).toEqual([]); + + }); + it('should allow paste tag from clipboard', function() { scope.taggingFunc = function (name) { return {