I am trying to get the value from a MatSelect, using rxjs fromEvent. I can't get it to pick up that an event has happened though. I have it working with MatInput, because I think that inherits default behaviour from the Html input element, but something is different with MatSelect.
If I swap out mat-select for a default select, the (change) event is picked up and it works as intended. (change) was apparently deprecated at some point on MatSelect, and no longer works.
I've tried moving the template ID to the mat-option to see if it could pick up an event from there, no luck. tried: (change) (select) (selectionChange) (valueChange)
@ViewChild('projectNameInput', {static: false, read: ElementRef}) projectNameInput: ElementRef;
@ViewChild('pipelineSelect', {static: false, read: ElementRef}) pipelineSelect: ElementRef;
@ViewChild('codeCoverageInput', {static: false, read: ElementRef}) codeCoverageInput: ElementRef;
ngAfterViewInit() {
// server-side search
const projectObs$ = fromEvent(this.projectNameInput.nativeElement, 'keyup');
const selectObs$ = fromEvent(this.pipelineSelect.nativeElement, 'onSelectionChange');
const coverageObs$ = fromEvent(this.codeCoverageInput.nativeElement, 'keyup');
const all$ = merge(projectObs$, selectObs$, coverageObs$)
.pipe(
debounceTime(300),
distinctUntilChanged(),
tap(() => {
this.paginator.pageIndex = 0;
this.loadSummariesPage();
})
)
.subscribe();
this.paginator.page
.pipe(
tap(() => this.loadSummariesPage())
)
.subscribe();
}
------------------------------------
<mat-form-field appearance="fill">
<mat-label>types</mat-label>
<mat-select name="type" [(ngModel)]="type">
<mat-option #x *ngFor="let option of options" [value]="option.value">
{{option.viewValue}}
</mat-option>
</mat-select>
</mat-form-field>