简体   繁体   中英

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.

Now.. the response of node.js back to Angular is formatted as json so an example could be (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?

Also if you need, this is what I did with node.js to send a response back formatted as 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?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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