使用RESTAPI
在Angular 2中,我正在努力发出RESTAPI请求 使用以下各项时,我的API本身可以工作:使用RESTAPI,rest,http,angular,Rest,Http,Angular,在Angular 2中,我正在努力发出RESTAPI请求 使用以下各项时,我的API本身可以工作: http://localhost:8080/tshirts 它将返回给我: [{ "Id": 1, "Title": "honey blanket", "PrintTechnique": "sublimation" }, { "Id": 2, "Title": "tell your story", "PrintTechnique": "screen print" }]
http://localhost:8080/tshirts
它将返回给我:
[{
"Id": 1,
"Title": "honey blanket",
"PrintTechnique": "sublimation"
}, {
"Id": 2,
"Title": "tell your story",
"PrintTechnique": "screen print"
}]
现在,我试着用Angular实现请求,灵感来自他们的:
根据我的界面,结果应为Tshirts[]
类型:
export interface Tshirt {
Id: number;
Title: string;
PrintTechnique: string;
}
但是,控制台不会打印Tshirt对象,而是打印一个可观察的
:
Observable {_isScalar: false}
_isScalar:false
_subscribe:(responseObserver)
__proto__:Object
我做错了什么?我认为可以观察到的响应需要通过以下方式映射:
this.http.request(...)
.map(response => response.json());
this.http.request(...)
.map(response => response.json());