简体   繁体   English

Angular ~“对象”类型上不存在属性“”

[英]Angular ~ Property '' does not exist on type 'Object'

Some days ago I have started working on an Angular project, and how my "infrastructure" works is: Angular (front-end) connects to the node.js server (back-end) which if needed sends a request or query to an api server or a mongo database. Some days ago I have started working on an Angular project, and how my "infrastructure" works is: Angular (front-end) connects to the node.js server (back-end) which if needed sends a request or query to an api server or一个mongo数据库。

Now.. the response of node.js back to Angular is formatted as json so an example could be (response = { "date": getDate() } ) .现在.. node.js对 Angular 的响应被格式化为json所以一个例子可以是(response = { "date": getDate() } ) The problem comes with how can I access that response or more specifically.. access the date child?问题在于如何访问该响应或更具体地说..访问日期孩子? This is how I did it:我是这样做的:

let url = "http://localhost:3000/checkdate"
this.http.post(url, data).subscribe((responsedata) => {
   console.log(responsedata.date);
})

The the 3th line is where the error stays at, and it says " Property 'date' does not exist on type 'Object'. ", anyone who can help me with it?第 3 行是错误所在的位置,它显示“属性 'date' 在类型 'Object' 上不存在。 ”,任何人都可以帮助我吗?

Also if you need, this is what I did with node.js to send a response back formatted as json:另外,如果您需要,这就是我对 node.js 所做的,以发送格式为 json 的响应:

app.post("/checkdate", (req, res) => {
    console.log("New post request recieved!");
    res.json({
        "date": "12.31.2000"
    })
})

I really don't seem to find a way or answer on the internet to solve this issue.我似乎真的没有在互联网上找到解决这个问题的方法或答案。

Thanks for your help and time!感谢您的帮助和时间!

Can you try responseData.obj.date?你可以试试 responseData.obj.date 吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM