这个问题可能是因为MatSelect组件没有正确地被更新。在选择记录后,可以尝试通过手动更改MatSelect的值来解决这个问题。以下是解决方法的示例代码:
HTML代码:
{{ option.viewValue }}
TypeScript代码:
import { Component } from '@angular/core';
import { FormControl } from '@angular/forms';
interface Option {
value: string;
viewValue: string;
}
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss']
})
export class AppComponent {
myControl = new FormControl();
options: Observable
在上述代码中,我们监听了选择改变事件,并更新了选中值和MatSelect的值。这将确保组件正确地被更新,以反映新的选中值。