728x90
반응형
app.module.ts 파일에서
아래 모듈, 함수 추가
import { NgModule, Injector, APP_INITIALIZER } from '@angular/core';
import { LOCATION_INITIALIZED } from '@angular/common';
import { TranslateModule, TranslateLoader, TranslateService } from '@ngx-translate/core';
import { TranslateHttpLoader } from '@ngx-translate/http-loader';
export function appInitializerFactory(
translate: TranslateService,
injector: Injector
) {
return () =>
new Promise<any>((resolve: any) => {
const locationInitialized = injector.get(
LOCATION_INITIALIZED,
Promise.resolve(null)
);
locationInitialized.then(() => {
const langToSet = 'ko';
translate.setDefaultLang(langToSet);
translate.use(langToSet).subscribe(
() => {
console.info(`Successfully initialized '${langToSet}' language.'`);
},
(err) => {
console.error(
`Problem with '${langToSet}' language initialization.'`
);
},
() => {
resolve(null);
}
);
});
});
}
providers 부분에 만든 factory 추가
providers: [
// ...
{
provide: APP_INITIALIZER,
useFactory: appInitializerFactory,
deps: [TranslateService, Injector],
multi: true,
}
]
728x90
반응형
'Programming > JavaScript & TypeScript' 카테고리의 다른 글
var VS let VS const 의 차이 (0) | 2020.09.14 |
---|---|
ECMAScript란? (0) | 2020.09.14 |
[Node.js-Mongo] MongoError: Exceeded memory limit for $, but didn't allow external sort. Pass allowDiskUse:true to opt in. 해결 (0) | 2020.09.11 |
ECMAScript 2020 (0) | 2020.09.10 |
[Javascript VS Typescript] 자바스크립트와 타입스크립트 중 뭐가 더 좋을까 (0) | 2020.09.10 |