Angular | Replace a service in the inner modules by a other class

Discussão em 'Angular' iniciado por AbuDawood Oussama, Novembro 13, 2024.

  1. Here is the full declaration of the nested module

    https://github.com/abpframework/abp...ng-packs/packages/core/src/lib/core.module.ts

    the source file we have three declared modules

    //BaseCoreModule
    @NgModule({
    ...
    import:[
    ...
    OAuthModule, // has the service that I want to replace by my own
    ...
    ]
    ...
    })
    export class BaseCoreModule {}


    //RootCoreModule
    @NgModule({
    exports: [BaseCoreModule, LocalizationModule],
    imports: [
    BaseCoreModule,//notice
    ...
    OAuthModule.forRoot(), // OAuthModule is imported again using forRoot()
    ...
    ],
    })
    export class RootCoreModule {}


    // CoreModule will be imported to the AppModule
    @NgModule({
    exports: [BaseCoreModule],
    imports: [BaseCoreModule],
    })
    export class CoreModule {
    static forRoot(options = {} as ABP.Root): ModuleWithProviders<RootCoreModule> {
    return {
    ngModule: RootCoreModule,
    providers: [...other providers...]
    }
    }
    }


    The CoreModule is imported in my AppModule using forRoot() function. What I want to do is to replace (override) a service provided in the OAuthModule which is deeply imported by the CoreModule without the necessity to use conventional methods (e.g. using source code instead of npm lib)

    Continue reading...

Compartilhe esta Página