내 서비스 TranslatorService의 생성자에서이 코드가 모든 응용 프로그램이나 on demande에 대해 한 번만 호출되며 모든 시간이 homecomponent가 아닌 경우로드가 수행되는 방법이 있습니까 ???? ???? 대한생성자 함수가 한 번만 실행되는지 어떻게 확인할 수 있습니까?
this.translations$ = translationsCollection.snapshotChanges().map(actions => {
return actions.map(a => {
...
})
번역 클래스 내 경우 FireStore의 예에서 PIN이 번역 :
{
"WELCOME": {
"FR": "bienvenue",
"GB": "Welcome"
}
}
export interface Translation {
[code: string]: TranslationInfo;
}
export interface TranslationInfo {
[language: string]: string;
}
내 핵심 모듈 appmodule 주입
import { NgModule } from '@angular/core';
import { AuthService } from './auth.service';
import { AngularFireAuthModule } from 'angularfire2/auth';
import { AngularFirestoreModule } from 'angularfire2/firestore';
import { TranslatorService } from '../services/translator.service';
@NgModule({
imports: [
AngularFireAuthModule,
AngularFirestoreModule
],
providers: [AuthService, TranslatorService]
})
export class CoreModule { }
@NgModule({
declarations: [
...
],
imports: [
...
CoreModule,
...
],
providers: [AuthGuard],
bootstrap: [AppComponent]
})
export class AppModule { }
내 통역 서비스
@Injectable()
export class TranslatorService {
translationsCollection: AngularFirestoreCollection<Translation>;
translations$: Observable<any>;
public translations: Translation[];
constructor(private afs: AngularFirestore) {
var translationsCollection = this.afs.collection("translations");
this.translations$ = translationsCollection.snapshotChanges().map(actions => {
return actions.map(a => {
...
})
});
내 구성 요소
export class HomeComponent implements OnInit {
translations$: Observable<any>;
constructor(private translator: TranslatorService) { }
ngOnInit() {
this.translations$ = this.translator.translations$;
}
내 구성 요소보기
<div *ngFor="let translation of translations$|async">
<pre>{{translation | json}}</pre>
</div>
좋은 생각으로 보입니다. 오늘이나 tommorow를 시도해 봅니다. – Yoamb
마침내 내 도로지도를 변경하고 ngx-translate를 선택하여 다중 언어를 관리합니다. – Yoamb
동일한 것을 사용하고 있지만 언어 관련 작업에 언어 구성 요소를 사용하고 있습니다. 특히 RTL을하고 있습니다. – user2842256