【发布时间】:2020-09-21 18:56:21
【问题描述】:
我正在尝试赋予我的角材质下拉菜单自己的风格。我正在使用 Angular 10。我做了很多研究并尝试了很多我可以在 Stackoverflow 和其他网站上找到的东西,但是当我从互联网上复制方法时,我的 mat-select 的样式并没有改变。这是我当前的代码:
import { Component, OnInit, ViewEncapsulation } from '@angular/core';
interface Radius {
value: number;
viewValue: string;
}
@Component({
selector: 'app-landing-page',
animations: [],
templateUrl: './landing-page.component.html',
styleUrls: ['./landing-page.component.scss'],
encapsulation: ViewEncapsulation.None
})
export class LandingPageComponent implements OnInit { // The dropdown menu containing component
// .....
radiusList: Radius[] = [
{value: -1, viewValue: "Nothing"},
{value: 5, viewValue: "5km"},
{value: 10, viewValue: "10km"},
{value: 15, viewValue: "15km"},
{value: 25, viewValue: "25km"},
{value: 50, viewValue: "50km"},
{value: 100, viewValue: "100km"},
]
selectedRadius: Radius;
// .....
}
// ---------------------------------
// app.module.ts
import {MatSelectModule} from '@angular/material/select';
// ...
@NgModule({
declarations: [
AppComponent,
LandingPageComponent
],
imports: [
BrowserModule,
FormsModule,
HttpClientModule,
AppRoutingModule,
ReactiveFormsModule,
BrowserAnimationsModule,
MatSelectModule
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
.test.mat-select-panel {
background: red; // also background-color does not work
}
<mat-form-field appearance="fill">
<mat-label>Umkreis</mat-label>
<mat-select panelClass="test" [(ngModel)]="selectedRadius" name="radius">
<mat-option *ngFor="let radius of radiusList" [value]="radius.value">
{{radius.viewValue}}
</mat-option>
</mat-select>
</mat-form-field>
有人可以提示我如何设置下拉菜单的样式吗?如果我使用 Angular Material 中的其他组件,这是否会在任何地方都一样?
提前谢谢你!
【问题讨论】: