I am writing an angular2 universal app. It has a d3 chart, but I was hoping to only render the d3 chart on the client side (browser) and not try to render it on the server. Is there an interface in angular2 universal that will only run a component method only on the client side?
i.e.
class ComponentWithChart implements OnInit, ngUniversalBrowser {
elem;
constructor( private viewContainerRef:ViewContainerRef) {}
ngUniversalBrowserOnInit() {
this.elem = this.viewContainerRef.element.nativeElement;
d3.select(this.elem).append('div').style({
'background-color':'yellow'
});
}
}
Is there anything like the example above that might allow me to only run the ngUniversalBrowser
method only in the browser OnInit
?