0
我有angular2代碼服務中獲得錯誤響應映射angular2
getkokabname(id){
let url = "http://localhost:8080/regencies/name/"+id;
let header = new Headers({'Content-Type': 'text/plain;charset=UTF-8'});
return this.http.get(url, {headers: header})
.map(this.extractData)
.catch(this.handleError);
}
private extractData(res:Response) {
let body = res.json();
return body || [];
}
private handleError(error:any) {
// In a real world app, we might use a remote logging infrastructure
// We'd also dig deeper into the error to get a better message
let errMsg = (error.message) ? error.message :
error.status ? `${error.status} - ${error.statusText}` : 'Server error';
console.error(errMsg); // log to console instead
return Observable.throw(errMsg);
}
,如果我使用郵遞員訪問的URL。它會像這個KABUPATEN SUMENEP一樣返回文本。但在我的代碼,它在位置0的JSON中返回意外的標記K.如何解決?
這裏是我的接入碼值
kokabname(){
this.service.getkokabname(this.gov).subscribe(
data=> this.governmentname = data,
err => err
)
}
感謝花花公子的答案 – dedypuji