Understanding the use of forRoot() in Angular2+

Asked

Viewed 22 times

0

Hello,

I don’t know if I understood very well what is in the Angular documentation, but from what I understood, when declaring a module in the app.module as for example FooModule.forRoot(), this module ends up being instantiated once at the root of the application and it is no longer necessary to declare it in other ngModules.

My first question is the counterpart.. What is lost when doing forRoot? Because if there is no loss it would make sense to always declare forRoot.

Another question I’m left with is if I do the @Injectable ({ providedIn: 'root' }) on Component is the same thing as doing forRoot on ngModule?!

And finally I have an application that uses, for example, the library 'Ngcircleprogress'. And in the documentation they speak to declare the NgCircleProgressModule.forRoot({}) in appModule. Only I use this library in only one component and this component is inside an Ngmodule that uses Lazyloading. Even considering that I will use this lib in only one component it makes sense to use forRoot?

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.