Angular condition in type provider with AOT
问题 I have an Angular project which I compile with AOT. I want to be able to register ClassProvider that is resolved dynamically according to configuration. Simplified code I use is this: const isMock = Math.random() > 0.5; @NgModule({ // ... providers: [ { provide: MyServiceBase, useClass: (isMock) ? MyServiceMock : MyService }, ], bootstrap: [AppComponent] }) export class AppModule { } The problem is when I compile this with AOT I always get the same service. I would expect to get different