What is the best solution to solve requestAnimationFrame is not defined in angular?
The requestAnimationFrame
is not defined” is an Angular universal server running issue. The best solution for this issue is to search for requestAnimationFrame and ensure it's only called when the user is in a browser, not in the server. We can do this by reviewing if there is a nativeElement present on a component ElementRef.
BY Best Interview Question ON 24 Jun 2020
Example
class blahComponent implements OnInit {
constructor(private elRef:ElementRef) { }
ngOnInit() {
if (this.elRef.nativeElement) {
/** here goes your code */
}
}
}