2

Given the following:

@NgModule( {} )
export class ServicesModule {
  static forRoot() {
    return {
      ngModule: ServicesModule,
      providers: [ ...moduleProviders ]
    }
  }
}

const moduleProviders = [ CountryService, DenomService];

export {CountryService, DenomService}

Is there some way in TypeScript or Angular2 that I could prevent the duplication of CountryService, DenomService in the moduleProviders and the export?

The spread operator works quite well in the providers: property, but using the spread in the export will not work as below

export { ...moduleProviders }

Any suggestion as to what I could do prevent the duplication mentioned.

Thanks

st_clair_clarke
  • 5,453
  • 13
  • 49
  • 75
  • Why are you exporting `CountryService` and `DenomService` from the ngModule file? Don't those services have their own files, such as `country.service.ts`? – BeetleJuice Nov 01 '16 at 02:36
  • Yes, They do. I merely use the code do demonstrate a wider concept I am looking at. Notwithstanding the unconventional code, is there a method to accomplish it. Thanks. – st_clair_clarke Nov 01 '16 at 04:13
  • Try to have a look at es6 export syntax, you could try to export * from 'country.Service' and export * from 'demo.Service' if this ehat are you looking for – Nicu Nov 01 '16 at 21:18

0 Answers0