I'm taking over the code of a small application witl Ionic v2, and I'm using ng2-translate
for my translations. I have an issue with translations only in a modal window. It works very well everywhere, except on this modal, where I can only see the transaltion keys.
Here is my AppModule
:
@NgModule({
declarations: [
MyApp,
// ...
SearchPersonModal
],
imports: [
IonicModule.forRoot(MyApp),
ChartModule,
TranslateModule.forRoot({
provide: TranslateLoader,
useFactory: (createTranslateLoader),
deps: [Http]
})
],
bootstrap: [IonicApp],
entryComponents: [
MyApp,
// ...
SearchPersonModal,
],
providers: [
ApiCaller
]
})
export class AppModule {}
The modal is used in the application for searching a user in the remote database. Here is the code of the modal component :
@Component({
selector: 'page-search-person',
templateUrl: 'search-person.html',
})
export class SearchPersonModal {
public caller : ApiCaller = null;
public translate : TranslateService = null;
// ..
constructor(
public viewCtrl: ViewController,
public toastr: ToastController,
params: NavParams
) {
this.translate = params.get('translate');
this.caller = params.get('caller');
}
// ...
}
And here is how the modal is presented :
let modal = this.modalCtrl.create(SearchPersonModal, {
caller: this.caller,
translate : this.translate
});
I think that the author of the code passed the services as parameters because dependency injection didn't work. In fact, when I try to do so, with this constructor :
export class SearchPersonModal {
//public caller : ApiCaller = null;
//public translate : TranslateService = null;
// ...
constructor(
public viewCtrl: ViewController,
public toastr: ToastController,
public caller: ApiCaller,
public translate: TranslateService,
params: NavParams
) {
//this.translate = params.get('translate');
//this.caller = params.get('caller');
}
// ...
}
the translation still doesn't work, but the ApiCaller
service works as expected. Why this service works well, but not the translator ?