【发布时间】:2020-09-02 12:11:35
【问题描述】:
我正在尝试读取这样的 JSON 配置文件
this.http.get('assets/env/env.json').pipe(map( res => res.json())).pipe(catchError((error: any): any => {
console.log('Configuration file "env.json" could not be read');
return Observable.throw(error.json().error || 'Server error');
})).subscribe( (envResponse) => {
endpoint="conf-" + envResponse.env + ".json";
alert(endpoint);
});
但是 res.json() 显示为错误
我正在导入这些类
import { Injectable } from '@angular/core';
import { HttpClient, HttpBackend } from '@angular/common/http';
import { map, catchError } from 'rxjs/operators';
import { Observable } from 'rxjs';
你能指出我做错了什么吗?
我的是 9 角
【问题讨论】:
-
这篇文章是你需要的吗? stackoverflow.com/questions/46630893/…