-
Notifications
You must be signed in to change notification settings - Fork 70
Load translations with promise, to allow preloading #30
base: master
Are you sure you want to change the base?
Conversation
src/http-loader.ts
Outdated
@@ -1,8 +1,11 @@ | |||
import {HttpClient} from "@angular/common/http"; | |||
import {TranslateLoader} from "@ngx-translate/core"; | |||
import "rxjs/add/operator/map"; | |||
import {Observable} from 'rxjs/Rx'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change the import to 'rxjs/Observable'
.
src/http-loader.ts
Outdated
*/ | ||
public preLoad(lang: string): Promise<any> { | ||
return new Promise((resolve, reject) => { | ||
this.http.get(`${this.prefix}${lang}${this.suffix}`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you can change the signature to:
get().subscribe(
result => ()....,
error => ()....
);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in this case better to use:
public preLoad(lang: string): Promise<any> {
return this.httpClient.get(`${this.prefix}${lang}${this.suffix}`)
.toPromise()
.then(result => {
this.loadedTranslations[lang] = result;
return result;
})
.catch(() => null);
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agree
@baso10 Can you make this changes? |
Guys, any updates? |
Still no updates on this? |
src/http-loader.ts
Outdated
@@ -1,7 +1,10 @@ | |||
import {HttpClient} from "@angular/common/http"; | |||
import {TranslateLoader} from "@ngx-translate/core"; | |||
import {Observable} from 'rxjs/Observable'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This has to be imported from 'rxjs'
Can we push it? |
@baso10 please make the changes on import and request as @akaNightmare has suggested so we can merge this into master. |
Guys, come on :D |
@ocombe can you merge this? |
We would really need this feature guys :D |
ping... |
With APP_INITIALIZER and Promise we can load translations before app is started.
Usage example: