javascript - 如何更改 matautocomplete 选项的字体颜色
问题描述
我想更改自动完成面板内显示的 mat-option 的字体颜色。
我在根 style.css 中定义了样式
::ng-deep .mat-option-text {
color: red !important;
}
但是,当我在浏览器检查元素面板中设置颜色属性时,我看到了变化
template.html 我应该在模板类或 style.css 中做哪些更改来更改 mat-options 的字体颜色。
<label>Search names</label>
<input type="text"
placeholder="search name"
aria-label="Number"
matInput
[formControl]="myControl"
[matAutocomplete]="auto">
<mat-autocomplete #auto="matAutocomplete">
<mat-option *ngFor="let option of filteredOptions | async" [value]="option">
{{option}}
</mat-option>
</mat-autocomplete>
模板.ts
import { Component, OnInit } from '@angular/core';
import { FormControl } from '@angular/forms';
import { Observable } from 'rxjs';
import { map, startWith } from 'rxjs/operators';
@Component({
selector: 'app-matautocom',
templateUrl: './matautocom.component.html',
styleUrls: ['./matautocom.component.css']
})
export class MatautocomComponent implements OnInit {
names: string[] = ['ghui', 'ustu', 'caty','momo', 'rekh', 'john', 'kemp'];
myControl: FormControl = new FormControl();
filteredOptions: Observable<string[]> | undefined;
constructor() { }
ngOnInit(): void {
this.filteredOptions = this.myControl.valueChanges.pipe(
startWith(''),
map(value => this._filter(value))
);
}
private _filter(value: string): string[] {
const filterValue = value.toLowerCase();
return this.names.filter((option) => {
console.log(filterValue)
option.toLowerCase().includes(filterValue);
return option;
})
}
}
解决方案
尝试这个
::ng-deep input.mat-input-element { 颜色:红色;}
或这个
::ng-deep .mat-option.mat-active { 颜色:红色;}
推荐阅读
- excel - 我自动化了一个进入谷歌并登录的代码,但我想下载的文件它的 ID 不断变化
- java - 在构造函数中计算时的同步
- cassandra - 我的大量表(2k+)会导致我的写入超时异常吗?
- spring - 访问 Spring WebClient 响应正文 **BEFORE** 被解析
- php - Laravel 在中间数据透视表上过滤最大日期
- glsl - 在 host->shader 和/或 shader->shader 之间传递 bvec2 数组
- c++ - 无法在动态链接库中找到过程入口点“_ZNSt7__...”。无论如何要解决而不将.dll复制到每个文件夹?
- javascript - 赛普拉斯在按钮被点击后愚蠢地等待新页面加载,甚至新页面的核心可操作资源都准备好了
- javascript - 如何重构为一个 API 调用以进行多个 mySQL 查询?
- oracle - 在oracle数据库中将字符串转换为base64