useClass vs useExisting

Stepan Suvorov picture Stepan Suvorov · Jul 17, 2017 · Viewed 15.9k times · Source

When should we use useExisting provider instead of useClass?

providers: [
{provide: Class1, useClass: Class1}, 
{provide: Class2, useExisting: Class2}]

REMARK: I have not found an exact question on SO. And for better indexing decided to create this specific one here, although I found this answers:

but would like to have more real examples

Answer

izik f picture izik f · May 10, 2018

useExisting - create refrence to service example here
useClass - create new instance of service example here