角度5サービスのhttp://samples.openweathermap.org/data/2.5/history/city?q=Warren,OH&appid=b6907d289e10d714a6e88b30761fae22からデータを取得中に次のエラーが発生しました。(未知のURL)のHTTPの失敗の応答:0角度5の不明なエラー
message: "Http failure response for (unknown url): 0 Unknown Error"
name: "HttpErrorResponse"
ok: false
status: 0
statusText: "Unknown Error"
ブラウザに直接api URLを入力すると、JSONオブジェクトリストが返されます。 私のサービスのコードはこちらweather.service.tsです。私はそれで間違って何が起こっているかを把握することはできませんapp.module.ts app.component.ts
import { Component } from '@angular/core';
import { WeatherService } from './weather.service';
import { Chart } from 'chart.js';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
constructor(private _weather: WeatherService) {}
ngOnInit() {
this._weather.dailyForecast()
.subscribe(res => {
console.log(res)
})
}
}
上
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { HttpClientModule } from '@angular/common/http';
import { WeatherService } from './weather.service';
import { AppComponent } from './app.component';
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
HttpClientModule
],
providers: [WeatherService],
bootstrap: [AppComponent]
})
export class AppModule { }
とコードの
import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http'
import 'rxjs/add/operator/map';
@Injectable()
export class WeatherService {
constructor(private _http: HttpClient) { }
dailyForecast() {
return this._http.get("http://samples.openweathermap.org/data/2.5/history/city?q=Warren,OH&appid=b6907d289e10d714a6e88b30761fae22")
.map(result => result);
}
}
コード。
こんにちは、私は同じ問題を抱えています。私が解決する方法をより良く説明できますか? –