import { Injectable } from '@angular/core';
import { Http,Response } from '@angular/http';
import {Observable} from 'rxjs/Observable';
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/catch';
import 'rxjs/add/observable/throw';
@Injectable()
export class CommentService{
private _url :string ="https://jsonplaceholder.typicode.com/posts"
constructor(private _http:Http){}
// method to fetch CommentS from a api service
getComments(){
return this._http.get(this._url)
.map((response:Response)=> response.json())
.catch(this._errorHandler);
}
_errorHandler(error:Response){
console.error(error);
return Observable.throw(error ||"Server Error");
}
}
上面的代碼的偉大工程這個網址https://jsonplaceholder.typicode.com/posts角2觀察到的JSON錯誤
但不與這個網址http://ergast.com/api/f1/2016/driverStandings.json
任何工作思路... TIA
你可以發佈什麼樣的錯誤你好嗎?我是你把https而不是http。我測試了第二個網址,它的工作原理。 – Coyote