在Angular Mat-Select中,如果想要避免选择已存储的值,你可以使用FormControl来控制Mat-Select的选择。下面是一个示例解决方法:
import { Component } from '@angular/core';
import { FormControl } from '@angular/forms';
@Component({
selector: 'app-your-component',
templateUrl: './your-component.component.html',
styleUrls: ['./your-component.component.css']
})
export class YourComponent {
// 定义FormControl对象
selectedValue = new FormControl('');
}
选择值
{{value}}
export class YourComponent {
options = ['选项1', '选项2', '选项3'];
selectedValue = new FormControl('');
}
这样,当你选择一个已存储的值时,Mat-Select将会自动更新为该值的索引,并且你无法再次选择相同的值。