我不知道如何在例如component.ts
。
我可以在color="primary
中使用template.html
或在mat-color($primary)
中使用style.scss
。但是,如何使用主题颜色为 Canvas 中的元素设置样式? 如何在TypeScript代码中使用它们?
信息:
"@angular/material": "^5.0.0-rc.2",
"@angular/core": "^5.0.0"
最佳答案
我使用了骇人听闻的解决方案。它不是很漂亮,但是可以正常工作。
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/