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

@NgModule() class instantiate #169

Open
artaommahe opened this issue Oct 29, 2016 · 4 comments
Open

@NgModule() class instantiate #169

artaommahe opened this issue Oct 29, 2016 · 4 comments

Comments

@artaommahe
Copy link
Contributor

There is some use-cases where some services don't have public methods and never used/injected by other components/services. This services inject other services and works with them on some events/etc. At ng1 we can use module.run() function to initialize this services, inject them at this function.
As i see at ng2 we can do this

@Injectable()
class SmthService {
  constructor() { console.log('SmthService'); }
}

@NgModule({
  providers: [ SmthService ],
})
export class AppModule {

  constructor(_smth: SmthService) {}
}

and this works as expected.
But looks like ng-metadata does not create module class instance and constructor is never called.
It would be useful to have modules classes instantiated.

@Hotell
Copy link
Member

Hotell commented Nov 15, 2016

just curious, can you provide some official docs or article where are they using NgModule class constructor for this kind of instantiation ? thx

@artaommahe
Copy link
Contributor Author

only this Ben Nadel post https://www.bennadel.com/blog/3180-ngmodule-constructors-provide-a-module-level-run-block-in-angular-2-1-1.htm

@Hotell
Copy link
Member

Hotell commented Nov 15, 2016

implementation Notes:

  • when bundle is called it should register ng1 .run hook with properly annotated injectables

@BhaskaranR
Copy link

dont think it is getting called ..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants