access SASS-Werte ($ colors from variables.scss) in Typescript (Angular2 ionic2)
n Ionic 2 möchte ich auf das @ zugreif$colors
Variablen aus der Datei "[mein Projekt] \ src \ theme \ variables.scss".
Diese Datei enthält:
$colors: (
primary: #387ef5,
secondary: #32db64,
danger: #f53d3d,
light: #f4f4f4,
dark: #222,
favorite: #69BB7B
);
In einer Komponente zeichne ich eine Leinwand. Es sieht so aus
import {Component, Input, ViewChild, ElementRef} from '@angular/core';
@Component({
selector: 'my-graph',
})
@View({
template: `<canvas #myGraph class='myGraph'
[attr.width]='_size'
[attr.height]='_size'></canvas>`,
})
export class MyGraphDiagram {
private _size: number;
// get the element with the #myGraph on it
@ViewChild("myGraph") myGraph: ElementRef;
constructor(){
this._size = 150;
}
ngAfterViewInit() { // wait for the view to init before using the element
let context: CanvasRenderingContext2D = this.myGraph.nativeElement.getContext("2d");
// HERE THE COLOR IS DEFINED AND I D LIKE TO ACCESS variable.scss TO DO THAT
context.fillStyle = 'blue';
context.fillRect(10, 10, 150, 150);
}
}
Wie man sehen kann, wird irgendwann in diesem Code die Farbe der Form definiert:context.fillStyle = 'blue'
, Ich möchte stattdessen etwas wie @ verwendcontext.fillStyle = '[variables.scss OBJECT].$colors.primary '
.
at jemand eine Ide