Dan*_*iel 8 typescript angular-ui angular-material angular-material2 angular
我不知道如何在 eg 中获得主要主题颜色(Angular Material)component.ts。
我可以color="primary在 mytemplate.html或mat-color($primary)a 中使用style.scss。但是如何使用主题颜色为画布内的元素设置样式?我如何在我的 TypeScript 代码中使用它们?
信息:
"@angular/material": "^5.0.0-rc.2",
"@angular/core": "^5.0.0"
Run Code Online (Sandbox Code Playgroud)
我使用了一个hacky解决方案。它不漂亮,但有效。
组件.html
<div #primary class="mat-button mat-primary" style="display:none"></div>
Run Code Online (Sandbox Code Playgroud)
组件.ts
declare let getComputedStyle: any;
export class Component implements AfterViewInit {
@ViewChild('primary') primary: ElementRef;
ngAfterViewInit() {
const primaryColor = getComputedStyle(this.primary.nativeElement).color;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4182 次 |
| 最近记录: |