在我的角度项目中有角度材料并使用mat-select.Mat-select是我的表格设置自动对焦的第一个元素,而页面已成功加载,但我无法在mat-select上设置自动对焦.任何人都可以帮我找到在mat-select中设置自动对焦的方法.
@ViewChild("name") nameField: ElementRef;
ngOninit() {
this.nameField.nativeElement.focus();
}
Run Code Online (Sandbox Code Playgroud)
HTML
<div>
<mat-select [(ngModel)]="nameField" #name>
<mat-option *ngFor="let option of options2" [value]="option.id">
{{ option.name }}
</mat-option>
</mat-select>
</div>
Run Code Online (Sandbox Code Playgroud) 我正在使用有角度的材料制作侧边栏菜单。我没有找到根据某些组件属性更改按钮颜色的方法。
我已经阅读了文档:https : //material.angular.io/components/button/overview
关于主题,它只说:
Buttons can be colored in terms of the current theme using the color property to set the background color to primary, accent, or warn.
这是我的代码:
<button
*ngFor="let link of links; let i = index"
mat-raised-button
color="primary"
(click)="selectedIndex = i"
[routerLink]="link.routerLink">
</button>
Run Code Online (Sandbox Code Playgroud)
我什至不知道是否有可能,但我正在寻找这样的东西:
<button
*ngFor="let link of links; let i = index"
mat-raised-button
(click)="selectedIndex = i"
[color]="selectedIndex === i ? primary : warm"
[routerLink]="link.routerLink">
</button>
Run Code Online (Sandbox Code Playgroud)