我想學習angular2(來自PHP腳本,這是相當困難^^),使用真正的休息api在「英雄之旅」。 從我讀,我認爲這可能是簡單的...angular2:問題與休息api
我有一個工作的API,建有快遞:
curl -XGET http://localhost:3001/heroes
[{"_id":"58185c8a8af4b512c51c0519","no":"1","name":"bahamut","__v":0,"updated_at":"2016-11-01T09:12:42.803Z"},{"_id":"58185ca78af4b512c51c051a","no":"2","name":"gatz","__v":0,"updated_at":"2016-11-01T09:13:11.063Z"},{"_id":"58185ec98af4b512c51c051b","no":"3","nam...
在hero.service.ts,我可以得到的數據:
getHeroes(): Promise<Hero[]> { // {{{
console.log('getheroes in service');
console.log("%o", this.http.get(this.heroesUrl).toPromise());
return this.http.get(this.heroesUrl)
.toPromise()
.then(response => response.json().data as Hero[])
.catch(this.handleError);
} // }}}
當我做同樣的console.log上原來的「英雄之旅」,我有數據的數組,而在這裏我有一個字符串... 我想我必須轉換某處字符串,但無論我嘗試,它不起作用。
(我看過很多例子與可觀測太多,但我也沒有成功)
幫助想解釋我如何... TIA
JP
什麼contentType的http:// localhost:3001/heroes迴應? – dfsq
你認爲JSON.parse(<你的響應字符串>) – OliverRadini