I'm working on an Angular 8 app, and we use global styles. I'm using the D3 chart library in the app and to set a style, you have to configure it in code. For example:
plottingArea.append('text')
.attr('fill', '#00B2B3');
This will change the color of the text used in the D3 graph (svg). But since we use global styles, I need to find a way to pull this value into code so that if the style changes at some point, I won't have to change the code.
I tried creating a class selector and adding the color there, then adding the class to the html element that's being used for the chart (in this case, a div), then using @ViewChild to query for the class to get the color property value:
component.scss
.my-color {
color: global-style('text', 'grey');
}
component.html
<div #my-div class="my-color"></div>
component.ts
@ViewChild('my-div', { static: false }) myDiv!: ElementRef;
ngAfterViewInit() {
//this returns empty string
const color = this.myDiv.nativeElement.style.color;
//this returns null
const style = this.myDiv.nativeElement.querySelector('.my-color');
}
So since I can't access the color value like that, I'm not sure how to do it.