Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/http/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 服务器上的角度可观测问题_Angular_Http_Angular2 Observables - Fatal编程技术网

Angular 服务器上的角度可观测问题

Angular 服务器上的角度可观测问题,angular,http,angular2-observables,Angular,Http,Angular2 Observables,我在Angular 6中创建了一个服务,它通过subscribe在ngOnInit上运行良好,但一旦我尝试通过函数/单击事件获得响应,我就会收到以下错误 错误DOMEException:未能在“XMLHttpRequest”上设置“responseType”属性:无法更改从文档发出的同步请求的响应类型 我怀疑我在做一些愚蠢的事情-数据在获取中返回良好。然后调用,所以我排除了服务器配置,到目前为止仍在使用角度理论,所以在这里发布,以防对经验丰富的人来说这是显而易见的 localhost它工作正常,

我在Angular 6中创建了一个服务,它通过subscribe在ngOnInit上运行良好,但一旦我尝试通过函数/单击事件获得响应,我就会收到以下错误

错误DOMEException:未能在“XMLHttpRequest”上设置“responseType”属性:无法更改从文档发出的同步请求的响应类型

我怀疑我在做一些愚蠢的事情-数据在获取中返回良好。然后调用,所以我排除了服务器配置,到目前为止仍在使用角度理论,所以在这里发布,以防对经验丰富的人来说这是显而易见的

localhost它工作正常,但当我将代码构建/移动到服务器时,会出现错误-有什么想法吗

问候 雷切尔

服务

export class GetVehicleResultsService {
  url = 'SOME_URL';
  constructor(private http: HttpClient) {}

  getVehicles() {
    return this
      .http
      .get<Vehicle>(`${this.url}`, {
        responseType: 'json',
        params: {
          keyword: '*'
        }
    });
  }
}

如果您使用的是
HttpClient
,则不需要
response.json()
,但这可能会给您带来不同的错误。哪一行给出了该错误?response.json()返回数据-来自测试函数的服务调用给出了错误-对不起,我的评论应该是清晰的。您如何从html模板调用test()方法?只需从按钮元素中单击一个(click)=“test()”
 ngOnInit() {
    this
      .getVehicleResultsService
      .getVehicles()
      .subscribe(
        vehicles => {
          this.vehicles = vehicles.response.docs;
          this.facets = vehicles.facet_counts.vcj_facet_fields;
      });
  }
// this call works and consoles the data 
  test() {

    fetch('SOME_URL')
  .then(response => response.json())
  .then(json => console.log(json));
  }
// this doesn't work

test() {
this
          .getVehicleResultsService
          .getVehicles()
          .subscribe(
            vehicles => {
              this.vehicles = vehicles.response.docs;
              this.facets = vehicles.facet_counts.vcj_facet_fields;
          });

      }