我正在写一个使用@ngx-translate的角度应用程序.使用TranslateModule.forRoot(...)我提供了TranslateLoader:
@NgModule({
imports: [
TranslateModule.forRoot({
loader: {
provide: TranslateLoader,
useFactory: HttpLoaderFactory,
deps: [HttpClient, ConfigService, LogService]
}
})
]
})
Run Code Online (Sandbox Code Playgroud)
我还有一个ConfigService,它使用APP_INITIALIZER加载一个config.json.
问题是,TranslateLoader需要配置中的url.但是forRoot()在APP_INITIALIZER之前运行,导致ConfigService没有加载配置和空URL.
还有另一种方法吗?
目前我正在考虑手动引导角度.
我正在尝试使函数变得通用。但我不明白为什么它这么说[E] Property 'displayName' does not exist on type 'T[{ [k in keyof T]: T[k] extends Base ? k : never; }[keyof T]]'。
interface Base {
id: string;
displayName: string;
}
interface Station extends Base {
district: Base;
city: Base;
}
type Item<T> = { [ k in keyof T ]: T[k] extends Base ? k : never }[keyof T] | 'self';
type Result = { displayName: string };
const f = <T extends Base>(items: Item<T>[], obj: T): Result[] …Run Code Online (Sandbox Code Playgroud)