ionic4ionic-cli

Ionic 4 CLI can't generate service


In my ionic 4 project directory I am doing

ionic g service api/login to create service through cli. But I am getting

[ERROR] type must be one of: component, directive, page, pipe, provider, tabs (not service) Use the --help flag for more details.

then I seek for help ionic g --help so it giving me these examples

Examples:

$ ionic g
$ ionic g
$ ionic g component
$ ionic g directive
$ ionic g page
$ ionic g pipe
$ ionic g provider
$ ionic g tabs
$ ionic g component foo
$ ionic g page Login
$ ionic g page Detail --no-module
$ ionic g page About --constants
$ ionic g pipe MyFilterPipe

I cannot see service anywhere. How can I generate service an alternative way is also fine if you can suggest.


Solution

  • Use the command argument “provider” instead of service:

    ionic g provider your-service 
    

    The terms provider and service are synonymous here.