Skip to content
This repository was archived by the owner on Oct 2, 2019. It is now read-only.

Commit 55cfc23

Browse files
authored
Merge pull request #251 from ivanvoznyakovsky/master
set default value to empty array
2 parents 3e25a48 + 5cee432 commit 55cfc23

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/uiSelectController.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ uis.controller('uiSelectCtrl',
201201
}
202202

203203
function setPlainItems(items) {
204-
ctrl.items = items;
204+
ctrl.items = items || [];
205205
}
206206

207207
ctrl.setItemsFn = groupByExp ? updateGroups : setPlainItems;

test/select.spec.js

+15
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,13 @@ describe('ui-select tests', function() {
259259
scope.$digest();
260260
}
261261

262+
it('should initialize selected choices with an array if choices source is undefined', function(){
263+
var el = createUiSelect(),
264+
ctrl = el.scope().$select;
265+
266+
ctrl.setItemsFn(); // setPlainItems
267+
expect(ctrl.items).toEqual([]);
268+
});
262269

263270
// Tests
264271
//uisRepeatParser
@@ -1816,6 +1823,14 @@ describe('ui-select tests', function() {
18161823
);
18171824
}
18181825

1826+
it('should initialize selected choices with an empty array when choices source is undefined', function(){
1827+
var el = createUiSelectMultiple({groupBy: "'age'"}),
1828+
ctrl = el.scope().$select;
1829+
1830+
ctrl.setItemsFn(); // updateGroups
1831+
expect(ctrl.items).toEqual([]);
1832+
});
1833+
18191834
it('should render initial state', function() {
18201835
var el = createUiSelectMultiple();
18211836
expect(el).toHaveClass('ui-select-multiple');

0 commit comments

Comments
 (0)