Skip to content

Commit

Permalink
fix(select): error if triggerValue is accessed from an empty select (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
crisbeto authored and kara committed Aug 23, 2017
1 parent ea143a0 commit 0526689
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/lib/select/select.spec.ts
Expand Up @@ -2184,6 +2184,13 @@ describe('MdSelect', () => {
expect(() => fixture.detectChanges()).not.toThrow();
}));


it('should not throw when the triggerValue is accessed when there is no selected value', () => {
const fixture = TestBed.createComponent(BasicSelect);
fixture.detectChanges();

expect(() => fixture.componentInstance.select.triggerValue).not.toThrow();
});
});

describe('change event', () => {
Expand Down
6 changes: 5 additions & 1 deletion src/lib/select/select.ts
Expand Up @@ -568,8 +568,12 @@ export class MdSelect extends _MdSelectMixinBase implements AfterContentInit, On

/** The value displayed in the trigger. */
get triggerValue(): string {
if (!this._selectionModel || this._selectionModel.isEmpty()) {
return '';
}

if (this._multiple) {
let selectedOptions = this._selectionModel.selected.map(option => option.viewValue);
const selectedOptions = this._selectionModel.selected.map(option => option.viewValue);

if (this._isRtl()) {
selectedOptions.reverse();
Expand Down

0 comments on commit 0526689

Please sign in to comment.