Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for adding a value provider to a NgModule using schematics #14608

Closed
EdricChan03 opened this issue May 31, 2019 · 4 comments
Closed

Add support for adding a value provider to a NgModule using schematics #14608

EdricChan03 opened this issue May 31, 2019 · 4 comments

Comments

@EdricChan03
Copy link

@EdricChan03 EdricChan03 commented May 31, 2019

🚀 Feature request

Description

I'm currently working on a library which is an HTTP wrapper of the YouTube Data v3 API: https://github.com/EdricChan03/ngx-ytd-api

Right now, I'm trying to add the ability for a developer to specify an API key to be used for all of the API classes. So far, I've supported that with an injection token, but I would like to simplify that for the developer with the ng-add schematic which would ask for an API key and declare that API key in the injection token accordingly.

However, I can't seem to find any way to import a value provider into the NgModule decorator. AFAIK, there's an addProviderToModule method in @schematics/angular/utility/ast-utils, but it only supports class providers:

/**
* Custom function to insert a provider into NgModule. It also imports it.
*/
export function addProviderToModule(source: ts.SourceFile,
modulePath: string, classifiedName: string,
importPath: string): Change[] {
return addSymbolToNgModuleMetadata(source, modulePath, 'providers', classifiedName, importPath);
}

Describe the solution you'd like

A custom method which would allow for a value provider to be added to a module.

Describe alternatives you've considered

  • Indicate that developers must specify the injection token manually, or set the API key explicitly for any calls to the API methods
  • Implement an internal provider in the module used (aka forRoot)
@alan-agius4
Copy link
Collaborator

@alan-agius4 alan-agius4 commented May 31, 2019

Hi, as far as I recall these methods fall under the private API.

That said, we definitely should provide a set of utility methods.

//cc @clydin please correctly if I am am wrong.

@FabienDehopre
Copy link

@FabienDehopre FabienDehopre commented Mar 18, 2020

any news on this feature request ?

@alan-agius4
Copy link
Collaborator

@alan-agius4 alan-agius4 commented Mar 18, 2020

Hi, the above mentioned method is part of the private API and is not intended to be used by 3rd parties.

If used externally, please be aware that they such methods can be removed/break in non major versions.

@angular-automatic-lock-bot
Copy link

@angular-automatic-lock-bot angular-automatic-lock-bot bot commented Apr 18, 2020

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.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Apr 18, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.