fix(select): error if triggerValue is accessed from an empty select (#6575)

This commit is contained in:
Kristiyan Kostadinov
2017-08-23 02:43:49 +02:00
committed by Kara
parent ea143a052f
commit 0526689fde
2 changed files with 12 additions and 1 deletions
+7
View File
@@ -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', () => {
+5 -1
View File
@@ -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();