我正在开发一个角度为6的项目,现在正面临一个问题! 我想读取可观察对象的内容,如下所示:
this.myService.getOne().subscribe(e => {
this.e = e;
console.log(this.e);
console.log(this.e.id); // result => undefined
});
我可以看到 this.e ,如下所示:
{"id":"1", "name":"myName", ...}
但是 this.e.id 是'undefined',当我写 this.e ['id'] 时也是一样。< / p>
你有什么主意吗?
答案 0 :(得分:0)
我发现了这个问题,我的getOne()方法中还有两件事:
我从更改了方法
getOne(): Observable<myObject> {...}
到
getOne() {...}
我更改了退货
this.get<myObject>(url, httpOptions); //httpOptions contained headers and response type 'text' as 'json'
到
this.get<myObject>(url);
现在功能正常,谢谢您的帮助! :)