简体   繁体   English

Ionic v5/Angular 8:HttpClient.get().subscribe() 返回 TypeError:无法读取未定义的属性“句柄”

[英]Ionic v5/Angular 8: HttpClient.get().subscribe() returns TypeError: Cannot read property 'handle' of undefined

HttpClient.get('...').subscribe((data:any) => { console.log(data) })) cause error and I am not able to find where the problem is. HttpClient.get('...').subscribe((data:any) => { console.log(data) })) 导致错误,我无法找到问题所在。 Please, do you have any idea what is going wrong?请问,你知道出了什么问题吗? I am Angular beginner.我是 Angular 初学者。

I get propably valid Observe object to the this.httpObserve subscribe on observe object cause this error.我得到有效的观察 object 到 this.httpObserve 订阅观察 object 导致这个错误。

ERROR TypeError: Cannot read property 'handle' of undefined (core.js:9110)
    at MergeMapSubscriber.project (http.js:1246)
    at MergeMapSubscriber._tryNext (mergeMap.js:46)
    at MergeMapSubscriber._next (mergeMap.js:36)
    at MergeMapSubscriber.next (Subscriber.js:49)
    at Observable._subscribe (subscribeToArray.js:3)
    at Observable._trySubscribe (Observable.js:42)
    at Observable.subscribe (Observable.js:28)
    at MergeMapOperator.call (mergeMap.js:21)
    at Observable.subscribe (Observable.js:23)
    at FilterOperator.call (filter.js:13)

----------- apicall.service.ts ----------------
import { Injectable } from '@angular/core';
import { HttpClient, HttpHandler, HttpClientModule } from '@angular/common/http';
import { Observable } from "rxjs";


@Injectable({
  providedIn: 'root'
})
export class ApicallService {
  httpObserve;
  httpHandler : HttpHandler;

  constructor() { }

  http = new HttpClient(this.httpHandler);

  public getData(val) : any {
    // test url
    this.httpObserve = this.http.get('https://www.seznam.cz');
    return this.httpObserve;
  }
}

----------- myapi.component.ts -------------------
import { Component, OnInit } from '@angular/core';
import { ApicallService } from '../apicall.service';
import { Observable } from "rxjs";

@Component({
  selector: 'app-myapi',
  templateUrl: './myapi.component.html',
  styleUrls: ['./myapi.component.scss'],
})

export class MyapiComponent implements OnInit {
  result : any;
  httpObserve;

  constructor() {}

  apicall = new ApicallService();

  ngOnInit(){}

  get(val): void {
    this.httpObserve = this.apicall.getData(val);
    this.httpObserve.subscribe((data:any) => { console.log(data) });
  }
}

page.ts

myapi = new MyapiComponent();
this.res = this.myapi.get(val);

you initiate without any value inside httpHandler .您在httpHandler内没有任何值就开始了。

http = new HttpClient(this.httpHandler); // <-- his.httpHandler is null

If there is no need for httpHandler ,如果不需要httpHandler

constructor(private http: HttpClient) { }

// remove httpHandler : HttpHandler;
// remove  http = new HttpClient(this.httpHandler);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Angular HttpClient获取方法订阅无法读取未定义的属性“长度” - Angular HttpClient get method subscribe Cannot read property 'length' of undefined 离子 5:TypeError:无法读取未定义的属性“订阅” - ionic 5 : TypeError: Cannot read property 'subscribe' of undefined 无法读取Ionic 4(Angular 8)上未定义的属性“ subscribe” - Cannot read property 'subscribe' of undefined on Ionic 4 , Angular 8 Angular - Ionic 2 - 无法读取未定义的属性“订阅” - Angular - Ionic 2 - Cannot read property 'subscribe' of undefined 角度测试和HttpClient:TypeError:无法读取未定义的属性“ get” - Angular testing and HttpClient: TypeError: Cannot read property 'get' of undefined Angular 2 TypeError:无法读取未定义的属性“ subscribe” - Angular 2 TypeError: Cannot read property 'subscribe' of undefined Angular 9 类型错误:无法读取未定义的属性“订阅” - Angular 9 TypeError: Cannot read property 'subscribe' of undefined HttpClient 返回“无法读取未定义的属性 &#39;get&#39;”[Angular 7] - HttpClient returns "Cannot read property 'get' of Undefined" [Angular 7] TypeError:无法读取未定义的Ionic 3 / Angular 5的属性“ get” - TypeError: Cannot read property 'get' of undefined Ionic 3 /Angular 5 Angular HttpClient 订阅无法读取未定义的属性“名称” - Angular HttpClient subscribe cannot read property 'name' of undefined
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM