Quantcast
Channel: Ionic Forum - Latest topics
Viewing all articles
Browse latest Browse all 70435

Ionic 5 translate loader external link failed

$
0
0

import { Injectable } from ‘@angular/core’;
import { TranslateLoader } from ‘@ngx-translate/core’;
import { APIURL } from “…/enum”
import { Observable } from ‘rxjs’;
import {HttpClient, HttpErrorResponse, HttpHeaders,HttpParams} from ‘@angular/common/http’;

@Injectable()
export class CustomTranslateLoader implements TranslateLoader {
contentHeader = new Headers({“Content-Type”: “application/json”,“Access-Control-Allow-Origin”:"*"});

constructor(private http: HttpClient) {}
getTranslation(lang: string): Observable<any>{

            const options = {
   headers: new HttpHeaders({ 'Content-Type':'application/json; charset=utf-8',"Access-Control-Allow-Origin":"*"}),
    params: new HttpParams(),
    reportProgress: false,

};

    var apiAddress = APIURL.LIVE+"static/i18n/"+ lang+".json";
    return Observable.create(observer => {
      this.http.get(apiAddress,options).subscribe((res: Response) => {
                observer.next(res.json());
                observer.complete();               
            },
        error => {
            //  failed to retrieve from api, switch to local
            this.http.get("/assets/i18n/en.json").subscribe((res: Response) => {
                observer.next(res.json());
                observer.complete();               
            })
        }
        );
    }); 
}

}

I am using above code…but external link getting failed to fetch data.if i open link with browser working fine please help me.

1 post - 1 participant

Read full topic


Viewing all articles
Browse latest Browse all 70435

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>