Skip to content

Commit 2ae2dfb

Browse files
committed
fix: reverted adding withHttpBackend
the new function practically saves the user 4 characters while adding a new function to the library with no practical use. ~~~ TranslateHttpLoader.withHttpBackend(httpBackend, '/assets/i18n/', '.json'), ~~~ vs ~~~ new TranslateHttpLoader(new HttpClient(httpBackend), '/assets/i18n/', '.json'), ~~~ It makes more sense to add this to the documentation.
1 parent 34ff089 commit 2ae2dfb

File tree

2 files changed

+5
-18
lines changed

2 files changed

+5
-18
lines changed

projects/http-loader/src/lib/http-loader-backend.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {
22
HTTP_INTERCEPTORS,
3-
HttpBackend,
3+
HttpBackend, HttpClient,
44
provideHttpClient,
55
withInterceptorsFromDi
66
} from "@angular/common/http";
@@ -32,7 +32,7 @@ describe('TranslateLoader (HttpBackend)', () => {
3232
loader: {
3333
provide: TranslateLoader,
3434
useFactory: (httpBackend: HttpBackend) =>
35-
TranslateHttpLoader.withHttpBackend(httpBackend, '/assets/i18n/', '.json'),
35+
new TranslateHttpLoader(new HttpClient(httpBackend), '/assets/i18n/', '.json'),
3636
deps: [HttpBackend],
3737
}
3838
}),

projects/http-loader/src/lib/http-loader.ts

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,17 @@
11
import {TranslateLoader, TranslationObject} from "@ngx-translate/core";
2-
import {HttpBackend, HttpClient} from "@angular/common/http";
2+
import {HttpClient} from "@angular/common/http";
33
import {Inject, Injectable} from "@angular/core";
44
import {Observable} from 'rxjs';
55

66
@Injectable()
77
export class TranslateHttpLoader implements TranslateLoader {
8-
9-
static readonly defaultPrefix = "/assets/i18n/";
10-
static readonly defaultSuffix = ".json";
11-
128
constructor(
139
private http: HttpClient,
14-
@Inject(String) public prefix = TranslateHttpLoader.defaultPrefix,
15-
@Inject(String) public suffix = TranslateHttpLoader.defaultSuffix
10+
@Inject(String) public prefix = "/assets/i18n/",
11+
@Inject(String) public suffix = ".json"
1612
)
1713
{}
1814

19-
public static withHttpBackend(
20-
backend: HttpBackend,
21-
prefix: string = TranslateHttpLoader.defaultPrefix,
22-
suffix: string = TranslateHttpLoader.defaultSuffix
23-
): TranslateHttpLoader
24-
{
25-
return new TranslateHttpLoader(new HttpClient(backend), prefix, suffix);
26-
}
27-
2815
/**
2916
* Gets the translations from the server
3017
*/

0 commit comments

Comments
 (0)