【发布时间】:2017-02-19 03:29:13
【问题描述】:
ufc-api.service.ts
getFighters() {
return this.http.get('http://ufc-data-api.ufc.com/api/v3/fighters')
.map(res => res.json());
}
fighter.component.ts
data: string;
constructor(private ufcApiService: UfcApiService) { }
clickGetFighter() {
this.ufcApiService.getFighters()
.subscribe(result => {
this.data = JSON.stringify(result);
},
error => {
this.data = error;
},
() => console.log('fighters done!!'));
}
它不起作用,我收到以下错误:
{ "_body": {}, "status": 0, "ok": false, "statusText": "", "headers": {}, "type": 3, "url": null }
如果我自己制作了 restful api,它就可以工作,但这是来自 UFC 数据 API 的网站。
有没有办法在 angular2 上使用 http get 获取 html 字符串,例如 .net 上的 HttpClient?
感谢您的帮助。
【问题讨论】: