useValue:
will assign the current any assigned instance of the object you provided.
useFactory
: It also does the same. You can customize the factory object based on another dependency inside the function
and before returning its instance.
{ provide: CustomDependency, useFactory: () => { if (IS_A) { return new A(); } else { return new B(); } } }
You can use useFactory
to customize your dependency during customization. Same as config
phase Angular 1, where you modify or form a dependency as needed.
source share