I don't know how to get the primary theme color (Angular Material) in a e.g. component.ts
.
I can use color="primary
in my template.html
or mat-color($primary)
in a style.scss
. But how do I use theme colors for styling an element inside a canvas? How do I use them inside my TypeScript-code?
Info:
"@angular/material": "^5.0.0-rc.2",
"@angular/core": "^5.0.0"
I used a hacky solution. It's not beautiful but working.
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;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With