Reputation: 13
I'm trying to build an Angular app with SSR, but I ran into problems with plotly.js. Here is the error I get:
C:\Users\x\Desktop\Angularapp\ngseo\dist\server.js:351783
var style = document.getElementById(id); ^
ReferenceError: document is not defined
Do you have any idea how to solve this error?
Upvotes: 0
Views: 374
Reputation: 1391
Try this in Angular 7
import {AfterViewInit, Component, ElementRef, ViewChild,Renderer2,OnInit} from '@angular/core';
@Component({
selector: 'my-app',
templateUrl: './app.component.html',
styleUrls: [ './app.component.css' ]
})
export class AppComponent implements OnInit {
constructor(private renderer: Renderer2, private el: ElementRef) {}
id='';
ngOnInit() {
this.id = this.el.nativeElement.getElementsByClassName('mydiv')[0];
console.log(this.id);
}
}
<p class="mydiv">
Start editing to see some magic happen :)
</p>
Upvotes: 1