Ng-packagr: Can't use services contained in my exported module as a stand alone service

Created on 24 Jan 2018  路  4Comments  路  Source: ng-packagr/ng-packagr

Type of Issue

[x] Bug Report
[ ] Feature Request

Description

I have created an ExportedModule, and contained within it is a service called DataService. I want to be able to inject it directly into the other application's providers array so that I can use it in my other components.

All of the exported components are working fine, and the DataService service works as expected (AKA, the components that utilize it work fine), but I am trying to use the DataService external to the components, so adding it to the providers array within the app.module.ts of the application that is using the exported module. Is there any way to do this? I have tried:

import { DataService } form 'ExportedModule';

But it says that the says there is no exported member DataService.

Below is how I'm currently writing the "ExportedModule"

  declarations: [
    QuestionSpaceComponent
  ],
  providers:[
    DataService
  ],
  exports: [
    QuestionSpaceComponent,
    DataService
  ]
})

_for bugs: please describe the error that you encountered_

_for features: please describe your use case_

How To Reproduce

_for bugs: please include instructions how to reproduce_

_Can you reproduce the error in the integration tests in ng-packagr?_
_If possible, take a look at the integration/samples and try to break one of these builds!_

_Is the error you faced in an application importing the library_
_Try to break the Angular CLI app聽in integration/consumers/ng-cli!_

Expected Behaviour

I expect to be able to inject DataService into the provider array in app.module.ts.
_for bugs: please describe what behaviour or result you expected_

_for features: do you have a first draft or an idea how to implement?_

Version Information

ng-packagr: x.y.z
@angular/*: x.y.z
typescript: x.y.z
rxjs: x.y.z
node: x.y.z
npm/yarn: x.y.z

_please include any version information that might be relevant, e.g. other third-party libraries_

question

All 4 comments

@clarknoah are you exporting your service in your public_api.ts? anything that you want available publically needs to be exported there

Trying that now, thanks so much for the fast reply, really appreciate it!

np also you shouldn't have to add your service to your other modules providers. it should already be available

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

_This action has been performed automatically by a bot._

Was this page helpful?
0 / 5 - 0 ratings

Related issues

BioPhoton picture BioPhoton  路  3Comments

hamedbaatour picture hamedbaatour  路  4Comments

ashley-hunter picture ashley-hunter  路  3Comments

alankin picture alankin  路  5Comments

hei-pa picture hei-pa  路  3Comments