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

[Question] Is it possible to bind Subscribers to Angular's DI system? #28

Open
JeongJun-Lee opened this issue Aug 16, 2018 · 0 comments

Comments

@JeongJun-Lee
Copy link

I tried to bind Subscriber to Angular DI like code below. But it look like not working, because this.auditsProv is always Undefined. If it's not impossible, should I have to use another DI for Subscribers like TypeDI(https://github.com/typeorm/typeorm-typedi-extensions)?

[post-subs.ts]
import { Injectable } from '@angular/core';
import { EventSubscriber, EntitySubscriberInterface, InsertEvent } from "typeorm";
import { AuditsProvider } from '../providers/audits/audits';

@Injectable()
@EventSubscriber()
export class PostSubscriber implements EntitySubscriberInterface {

constructor(private auditsProv: AuditsProvider) {
console.log(this.auditsProv);
}

/**

  • Called before entity insertion.
    */
    beforeInsert(event: InsertEvent) {
    console.log(BEFORE ENTITY INSERTED: , event.entity);
    this.auditsProv.save();
    }

}

[app.module.ts]
@NgModule({
declarations: [
MyApp,
HomePage
],
imports: [
BrowserModule,
IonicModule.forRoot(MyApp)
],
bootstrap: [IonicApp],
entryComponents: [
MyApp,
HomePage
],
providers: [
StatusBar,
SplashScreen,
{provide: ErrorHandler, useClass: IonicErrorHandler},
AuditsProvider,
PostSubscriber
]
})
export class AppModule {}

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

No branches or pull requests

1 participant