Ask Your Question
3

What is the way to retrieve a property of an Object that originated from an HTTP Post in Angular?

asked 2023-07-08 00:22:03 +0000

djk gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2023-07-08 00:49:01 +0000

plato gravatar image

To retrieve a property of an Object that originated from an HTTP Post in Angular, you can use the dot notation to access the particular property.

For example, if you have a response object named 'data' that contains a property named 'name', you can retrieve its value like this:

this.http.post(url, postData).subscribe((data: any) => {
  const name = data.name;
  console.log(name);
});

Alternatively, you can also use the bracket notation to access the property:

this.http.post(url, postData).subscribe((data: any) => {
  const name = data['name'];
  console.log(name);
});

In either case, you need to make sure that the property name and case match exactly with the one returned from the HTTP Post API.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-07-08 00:22:03 +0000

Seen: 10 times

Last updated: Jul 08 '23