[英]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.