Skip to content
This repository has been archived by the owner on Aug 29, 2023. It is now read-only.

Commit

Permalink
fix(chips): use empty chip buffer if not a string (#9885)
Browse files Browse the repository at this point in the history
Fixes #9867.
  • Loading branch information
devversion authored and kara committed Nov 16, 2016
1 parent e1a5146 commit d774b76
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
13 changes: 13 additions & 0 deletions src/components/chips/chips.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1224,6 +1224,19 @@ describe('<md-chips>', function() {
expect(scope.items.length).toBe(4);
expect(scope.items[3]).toBe('Grape');
}));

it('should use an empty string if ngModel value is falsy', inject(function($timeout) {
var element = buildChips(NG_MODEL_TEMPLATE);
var ctrl = element.controller('mdChips');

$timeout.flush();

var ngModelCtrl = ctrl.userInputNgModelCtrl;

expect(ngModelCtrl.$viewValue).toBeFalsy();
expect(ctrl.getChipBuffer()).toBe('');
}));

});

describe('without ngModel', function() {
Expand Down
11 changes: 7 additions & 4 deletions src/components/chips/js/chipsController.js
Original file line number Diff line number Diff line change
Expand Up @@ -383,12 +383,15 @@ MdChipsCtrl.prototype.useOnSelectExpression = function() {
* model of an {@code md-autocomplete}, or, through some magic, the model
* bound to any inpput or text area element found within a
* {@code md-input-container} element.
* @return {Object|string}
* @return {string}
*/
MdChipsCtrl.prototype.getChipBuffer = function() {
return !this.userInputElement ? this.chipBuffer :
this.userInputNgModelCtrl ? this.userInputNgModelCtrl.$viewValue :
this.userInputElement[0].value;
var chipBuffer = !this.userInputElement ? this.chipBuffer :
this.userInputNgModelCtrl ? this.userInputNgModelCtrl.$viewValue :
this.userInputElement[0].value;

// Ensure that the chip buffer is always a string. For example, the input element buffer might be falsy.
return angular.isString(chipBuffer) ? chipBuffer : '';
};

/**
Expand Down

0 comments on commit d774b76

Please sign in to comment.