令人惊讶的是我找不到onselect回调函数,那么我如何在material-angular-select上创建回调函数?
这是我的尝试
import { Component, Input, Output, OnInit, OnChanges, SimpleChanges, ChangeDetectionStrategy, EventEmitter } from '@angular/core';
import { BehaviorSubject } from 'rxjs/BehaviorSubject';
import { FormControl } from '@angular/forms';
import { MatSelectModule } from '@angular/material/select';
@Component({
selector: 'app-search-navigator',
template: `
<mat-form-field>
<mat-select [(value)]="selected" [formControl]="pc" panelClass="example-panel-{{pc.value}}">
<mat-option *ngFor="let panelColor of panelColors" [value]="panelColor.value">
{{ panelColor.viewValue }}
</mat-option>
</mat-select>
</mat-form-field>
`,
changeDetection: ChangeDetectionStrategy.Default
})
export class SearchNavigatorComponent implements OnInit {
private selected ;
private selectedObs$;
private pc = new FormControl('red');
private panelColors = [
{value: 'red', viewValue: 'red'},
{value: 'blue', viewValue: 'blue'},
{value: 'green', viewValue: 'green'}
];
constructor() {}
ngOnInit() {
this.selectedObs$ = new BehaviorSubject<any>(this.selected);
this.selectedObs$.subscribe((aselected) => {
console.log(aselected);//Nothing happens on select :(
});
}
}
<mat-select placeholder="Favorite food" [(ngModel)]="selectVal" (ngModelChange)="changeSelect()">
- Sachila Ranawaka