top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

Angular 2.0: What is the difference between a module's forRoot() and forChild() methods and why do we need it?

0 votes
866 views
Angular 2.0: What is the difference between a module's forRoot() and forChild() methods and why do we need it?
posted Dec 4, 2017 by Jdk

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

Call forRoot for root application module, AppModule. Calling it in any other module, particularly in a lazy loaded module

forRoot creates a module that contains all the directives, the given routes, and the router service itself.

Call forChild for child modules.

forChild creates a module that contains all the directives and the given routes, but does not include the router service.

answer Jan 24, 2018 by Manish Tiwari
...