mirror of
https://github.com/angular/angular.git
synced 2026-09-14 13:54:52 +08:00
fix(select): error if triggerValue is accessed from an empty select (#6575)
This commit is contained in:
committed by
Kara
parent
ea143a052f
commit
0526689fde
@@ -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', () => {
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user