Home > Back-end >  Angular: is it possible to use optional useClass in provides, in my case only load GlobalErrorHandle
Angular: is it possible to use optional useClass in provides, in my case only load GlobalErrorHandle

Time:03-08

So I got this code which works great to handle errors, only that I only want to load it when I am not developing, is it possible to set a load condition for useClass in providers:

providers: [
        {
            provide: ErrorHandler, // if in dev mode don't load this
            useClass: GlobalErrorHandler
        }

thanks

Sean

CodePudding user response:

Setup Environments, and export an environment variable in case of dev environment. (empty object in case of production / staging environment)

CodePudding user response:

export function provideGlobalErrorHandler() {
    if (Lib.DevMode()) {
        return {
            provide: ErrorHandler,
            useClass: GlobalErrorHandler
        };
    }
}
  • Related