Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/http/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用RESTAPI_Rest_Http_Angular - Fatal编程技术网

使用RESTAPI

使用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" }]

在Angular 2中,我正在努力发出RESTAPI请求

使用以下各项时,我的API本身可以工作:

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());