Indraraj26
Indraraj26

Reputation: 1966

set DATE_PIPE_DEFAULT_TIMEZONE with useFactory

I am trying to set custom timezone via useFactory that causing an error that timeZone.replace is not a function. But with useValue it is working fine.

@Injectable({ providedIn: 'root' })
class Foo {
  bar() {
    return new Promise((resolve) => {
      setTimeout(() => {
        resolve('-0400');
      }, 1000);
    });
  }
}
 providers: [
    {
      provide: DATE_PIPE_DEFAULT_TIMEZONE,
      deps: [Foo],
      // useValue: '-0400',
      useFactory: async (foo: Foo) => {
        return foo.bar();
      },
    },
  ],

See the app.module.ts
Playground: angular default timezone stackblitz

Upvotes: 0

Views: 883

Answers (0)

Related Questions