Junior From PDF Angular Angular

What is the purpose of the forRoot() and forChild() methods in Angular?

  • Used mainly by feature modules that provide services and routes.
  • forRoot() configures and provides singleton services for the app. Usually called

in the root module.

  • forChild() configures child routes without providing new service instances.

Example:

RouterModule.forRoot(routes) // for root app routing

RouterModule.forChild(childRoutes) // for feature module routing

More from Angular Tutorial

All questions for this course
Toolliyo Assistant
Ask about tutorials, ebooks, training, pricing, mentor services, and support. I use public site content only—not admin or internal tools.

care@toolliyo.com

Need callback? Share your details