从网址角度使用JSON加载自定义翻译

时间:2020-09-29 14:43:01

标签: angular typescript ngrx ngx-translate

下面的代码负责从url加载翻译,但是他们必须联系向我返回json的终结点,但是在这种情况下,翻译没有加载是什么原因?

TypeScript:

@Injectable({
  providedIn: 'root'
})
export class TranslationService implements TranslateLoader {

  constructor(private http: HttpClient, private globalService: GlobalService) {}

    getTranslation(): Observable<any> {
      const urlTocall = url
      const authorizationData = 'Basic ' + btoa(user + ':' + pwd);
      const headerOptions = {
        headers: new HttpHeaders({
            'Content-Type':  'application/json',
            Authorization: authorizationData
        })
    };
    
      return this.http.get(urlTocall, headerOptions ).pipe(map((res: any) => {
          return res.data.map(item => {
            return item.attributes.documento;
          });
      }));
    }
}

0 个答案:

没有答案