【发布时间】:2018-11-21 03:33:17
【问题描述】:
大家好,请帮助我,我有 Json 字符串,这是我从 Node api 获取的。我只想要该字符串中的单个值。
我有 service.ts,我从中调用 api 并订阅我的组件文件上的数据。
Json 字符串为 [{"_id":5,"name":"ram,shyam,kamal,kishore"}]
我只想要名称值。如何做到这一点。
service.ts 代码如下
empservicecall() {
return this.http.get("http://localhost:3000/api/Employee")
}
component.ts 代码如下
GetEmpName(){
this.Emp.empservicecall()
.subscribe(
response =>{
this.name=response.json})
}
它不起作用,并且此代码中的 response.json() 行也出现错误。 请帮帮我
【问题讨论】:
-
您使用的 Angular 的确切版本是什么?
-
你试过
response[0].name吗? -
@SiddAjmer 我正在使用 Angular 4
-
4.什么? 4.0 还是 4.3?
-
localhost:3000/api/Employee 是否只返回员工姓名?