我不知道如何获得主要主题颜色( Angular Material ),例如组件.ts
。
我可以在我的 template.html
中使用 color="primary
或在 样式中使用
。但是我如何使用主题颜色为 Canvas 内的元素设置样式?我如何在我的 TypeScript 代码中使用它们?mat-color($primary)
.scss
信息:
"@angular/material": "^5.0.0-rc.2",
"@angular/core": "^5.0.0"
最佳答案
我使用了一个 hacky 解决方案。它不漂亮但很有效。
component.html
<div #primary class="mat-button mat-primary" style="display:none"></div>
component.ts
declare let getComputedStyle: any;
export class Component implements AfterViewInit {
@ViewChild('primary') primary: ElementRef;
ngAfterViewInit() {
const primaryColor = getComputedStyle(this.primary.nativeElement).color;
}
关于angular - 如何在 TypeScript/JavaScript 中使用 Angular Material 主题颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47791591/