要在Angular中实现在选择后显示可见的MatIcon的MatSelect,可以按照以下步骤进行操作:
npm install @angular/material @angular/cdk @angular/animations
npm install @angular/material-moment-adapter moment
npm install @angular/material-icon
import { MatSelectModule } from '@angular/material/select';
import { MatIconModule } from '@angular/material/icon';
@NgModule({
imports: [
MatSelectModule,
MatIconModule
],
...
})
export class AppModule { }
Select an option
{{ option.icon }}
{{ option.label }}
import { Component } from '@angular/core';
@Component({
...
})
export class AppComponent {
options = [
{ value: 'option1', icon: 'home', label: 'Option 1' },
{ value: 'option2', icon: 'work', label: 'Option 2' },
{ value: 'option3', icon: 'school', label: 'Option 3' }
];
selectedOption: string;
}
通过以上步骤,就可以在选择后显示可见的MatIcon的MatSelect了。根据选择的选项,相应的图标将显示在选择框中。