Provider vs Service in CLI

Hi everyone,

Why does ionic cli generate Provider and Angular one does generate Service ?

Thanks !

4 Likes

What do you mean with this sentence?

With Ionic CLI

Command : ionic generate provider test
Class name in result : TestProvider

With Angular CLI

Command : ng g service test
Class name in result : TestService

Kneejerk reply: Because you asked Ionic to create a Provider, and Angular to create a Service… :stuck_out_tongue:

But you are asking why a Angular “Service” is called “Provider” in Ionic land.

Good question.

My guess: When Ionic went for this naming convention the Angular “best practices” weren’t pinned down yet, and provider was a common name with Ionic1/AngularJS, so they went with that. Maybe also because services are quite often used to provide data to pages in Ionic… but that’s just another wild guess.

3 Likes

They’re really the same thing. Just a name difference.

8 Likes

Thanks @mhartington.

But, like @Sujan12 said previously : Why a Angular “Service” is called “Provider” in Ionic land ?

We went with provider because when you want to include them in your ngModule, they go in the providers array :smile:

Can’t answer for Angular, but I’m going to guess it’s because in AngularJS, you have angular.service, so it makes it may make it easier to understand what it does.

5 Likes

@mhartington, any plans to re-align with Angular ? To me, ionic is an extension of Angular, and I would love to have them perfectly aligned

3 Likes

I think the same, also each time I return to an Ionic project after a long pause I have to rethink again… "is this suppose to be provider or service???

2 Likes

Finally found peace with Providers vs Service in ionic.

7 Likes