2
I am working on two projects, one does not work generate Preview and the other does not work generate service. Can anyone tell me the difference? What should I change to the latest? service is the latest? Which package or version should I use?
2
I am working on two projects, one does not work generate Preview and the other does not work generate service. Can anyone tell me the difference? What should I change to the latest? service is the latest? Which package or version should I use?
2
In Ionic, at least in version 3, the Provider
, but both are the same thing. That’s just a convention used in framework. So much Provider
as Service
use the same developer for dependency injection.
import { Injectable } from '@angular/core';
If you try to generate a service using Ionic CLI, the following will happen:
$ ionic generate service test
[ERROR] type must be one of: component, directive, page, pipe, provider, tabs (not service)
Use the --help flag for more details.
It does not recognize service as a parameter for the command.
Ps: In version 4 it is possible to use service as a parameter, as was said in the other reply.
1
In practice, both have the same functionality but in Ionic 4 it adopts the nomenclature of Service
, while in Ionic 3, it is called Provider
.
Of differences, in Ionic 3, the generated file is nomedoprovider.ts
, already in Ionic 4 would be nomedoservico.service.ts
.
If you are wanting to use the code of a Provider
in Ionic 4, you need to modify the class decorator @Injectable()
for:
@Injectable({
providedIn: 'root'
})
On which to use, even in Ionic 3, I create my own Providers
with the same nomenclature as a Service
, just as a matter of preference. About which version to use, I suggest that post (in English) and that (in Spanish) which tells a bit of the differences between the versions.
If you want to delve deeper into how to migrate from Ionic 3 to 4, I suggest you official migration documentation (in English) from Ionic.
Browser other questions tagged ionic
You are not signed in. Login or sign up in order to post.