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

Commit d774b76

Browse files
devversionkara
authored andcommitted
fix(chips): use empty chip buffer if not a string (#9885)
Fixes #9867.
1 parent e1a5146 commit d774b76

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

src/components/chips/chips.spec.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1224,6 +1224,19 @@ describe('<md-chips>', function() {
12241224
expect(scope.items.length).toBe(4);
12251225
expect(scope.items[3]).toBe('Grape');
12261226
}));
1227+
1228+
it('should use an empty string if ngModel value is falsy', inject(function($timeout) {
1229+
var element = buildChips(NG_MODEL_TEMPLATE);
1230+
var ctrl = element.controller('mdChips');
1231+
1232+
$timeout.flush();
1233+
1234+
var ngModelCtrl = ctrl.userInputNgModelCtrl;
1235+
1236+
expect(ngModelCtrl.$viewValue).toBeFalsy();
1237+
expect(ctrl.getChipBuffer()).toBe('');
1238+
}));
1239+
12271240
});
12281241

12291242
describe('without ngModel', function() {

src/components/chips/js/chipsController.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -383,12 +383,15 @@ MdChipsCtrl.prototype.useOnSelectExpression = function() {
383383
* model of an {@code md-autocomplete}, or, through some magic, the model
384384
* bound to any inpput or text area element found within a
385385
* {@code md-input-container} element.
386-
* @return {Object|string}
386+
* @return {string}
387387
*/
388388
MdChipsCtrl.prototype.getChipBuffer = function() {
389-
return !this.userInputElement ? this.chipBuffer :
390-
this.userInputNgModelCtrl ? this.userInputNgModelCtrl.$viewValue :
391-
this.userInputElement[0].value;
389+
var chipBuffer = !this.userInputElement ? this.chipBuffer :
390+
this.userInputNgModelCtrl ? this.userInputNgModelCtrl.$viewValue :
391+
this.userInputElement[0].value;
392+
393+
// Ensure that the chip buffer is always a string. For example, the input element buffer might be falsy.
394+
return angular.isString(chipBuffer) ? chipBuffer : '';
392395
};
393396

394397
/**

0 commit comments

Comments
 (0)