Could someone explain me the difference between
bootstrap(MyApp, [provide(Service1, { useClass: Service1})]);
and
bootstrap(MyApp, [Service1]);
Could someone explain me the difference between
bootstrap(MyApp, [provide(Service1, { useClass: Service1})]);
and
bootstrap(MyApp, [Service1]);
There isn't really a difference.
Using this version
bootstrap(MyApp, [provide(Service1, { useClass: Service1})]);
only makes sense when the classes differ, like
bootstrap(MyApp, [provide(XHRBackend, { useClass: MockBackend})]);
to pass a MockBackend when an XHRBackend is requested (is the type of the constructor parameter.
constructor(private backend:XHRBackend) {}
would get a MockBackend instance passed in.
If you just want to pass Service1 when Service1 is requested
bootstrap(MyApp, [Service1]);
will do.
It's exactly the same. You can use it when the token used for the provider is the class itself. If you watnt to provide something else behind the provider token, you can use the provide function with useClass, useValue, useExisting or useFactory.
Here are some samples that can interest you:
You could also have a look at the documentation of the Provider class: