Angular-cli: More help with providing services

Created on 3 Dec 2016  路  8Comments  路  Source: angular/angular-cli

OS?

Mac OSX Sierra

Versions.

angular-cli: 1.0.0-beta.21
node: 6.9.1
os: darwin x64

Repro steps

ng new foo
cd foo
ng g s bar

Suggestion

A warning message is shown that says
WARNING Service is generated but not provided, it must be provided to be used

Perhaps we can extend this to say

WARNING Service is generated but not provided, it must be provided to be used. Consider providing it in the closest NgModule [put module name here]. Read this link for more information about where to provide services [link to docs]

Details

I think not providing the service is correct behavior for the CLI because it is not clear cut. But adding suggestions and/or a link to docs may help the user.

3 (nice to have)

Most helpful comment

ng g s services/apiservices --module=app.module

All 8 comments

+1

+1 - clambered around why this wasn't working from the CLI turns out it was me moving files around and not receiving correct warnings, but this pointed me right at what I was missing. So no googling would have been required.

This could also be used when generating services: #3806

For services, I was thinking maybe a --provide option with support for several (tentatively named) keywords:

  • closest-module [default]
  • closest-component
  • root

For now I'm content with the warning showing when no additional config is provided and allowing the path of a module to be specified. Providing to a component is an approach that can be manually taken after viewing the provided warning.

When generating a service you can now specify where it will be provided with this PR #3811

ng g s services/apiservices --module=app.module

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

_This action has been performed automatically by a bot._

Was this page helpful?
0 / 5 - 0 ratings