我目前正在处理有角度的http调用,起初我使用内存api创建服务,但后来删除了所有内存依赖项以集成实际的Java服务。在模块和组件文件中删除了内存api的依赖关系后,我得到“找不到集合'1bvzxg'”的错误,请您想知道我该如何解决。 还重做了组件和服务文件以调用免费的天气api,我仍然遇到相同的问题,
这是我的服务文件
import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Http } from "@angular/http";
import { Observable, of, throwError, pipe } from 'rxjs';
import { catchError, tap, map, mergeMap } from 'rxjs/operators';
import {PolicyData} from '../../../../core/models/policy'
@Injectable(
{
providedIn: 'root'
}
)
export class PolicyService {
constructor(private http: HttpClient) { }
private weatherUrl: string = 'https://api.myjson.com/bins/1bvzxg';
policy_endpoint = 'config';
getWeather():Observable<PolicyData> {
console.log('getting weather');
return this.http.get<PolicyData>(this.weatherUrl)
.pipe(
tap(data => console.log('getPolicyInfo:'+JSON.stringify(data)))
)
}}
这是组件代码
export class PolicyComponent implements OnInit { config: PolicyData; constructor(public snackBar: MatSnackBar, private policyService: PolicyService) getWeather() {
this.policyService.getWeather()
.subscribe(
(config: PolicyData) => config, // success path
(err: any) => console.log(err),
() => console.log('all done right')
);
}
这是HTML调用
<button mat-button color="primary" style="left:0%" type="button" (click)="getWeather()"><h3>Let Me Choose My Vehicle</h3></button>
请检查并指导我在这,在此先感谢...