Loading…

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.

Example

                                        

class blahComponent implements OnInit {
    constructor(private elRef:ElementRef) { }

    ngOnInit() {
        if (this.elRef.nativeElement) {
           /** here goes your code */
        }
    }
}

Suggest An Answer

No suggestions avaliable!

Latest post from Angular 2 Interview Questions

Ask Question