Created
February 22, 2017 14:56
-
-
Save travisfont/703fc80c8fa587223663e49319b05a9e to your computer and use it in GitHub Desktop.
Using Renderer and setElementClass/setElementStyle APIs (Web, Server, WebWorker)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export class SongTrack | |
{ | |
constructor( | |
private element: ElementRef, | |
private renderer: Renderer | |
) | |
{ | |
let elem = this.element.nativeElement; | |
renderer.setElementStyle(elem, "color", "blue"); | |
renderer.setElementClass(elem, "selected", true); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
A safer alternative to ElementRef to set our styling is to use the Renderer together with setElementClass and setElementStyle. Their implementation will abstract the underlying platform being used overcoming the compatibility limitation from ElementRef.