Skip to content

Instantly share code, notes, and snippets.

@travisfont
Created February 22, 2017 14:56
Show Gist options
  • Save travisfont/703fc80c8fa587223663e49319b05a9e to your computer and use it in GitHub Desktop.
Save travisfont/703fc80c8fa587223663e49319b05a9e to your computer and use it in GitHub Desktop.
Using Renderer and setElementClass/setElementStyle APIs (Web, Server, WebWorker)
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);
}
}
@travisfont
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment