Getting fields from JSON using Angularjs

This is a very simple question, but I am writing a web page that should display user information. The fields name, id, role, etc. will appear. I want to write the setter and getter methods for JSON that I get from the database. For example, if I get JSON and I want to get and display the name field, how would I write this getter method in angularJS after receiving JSON from the $ resource service?

This is an example of what JSON looks like:

[{"name": "Jason"
  "date of birth": "february 23, 2985"
  ....
 }]

Again, I just want to know how to write a getter method if I want to get a name field.

0
source share
1 answer

Should be like javascript.

var result = [{"name": "Jason"
  "date of birth": "february 23, 2985"
  ....
 }];

var firstResultsName = result[0].name;

, . .

[{"name": "Jason", <<-- this comma is necessary to work correctly.
"date of birth": "february 23, 2985",  <<-- and this one.

, , .

+3

Source: https://habr.com/ru/post/1546763/


All Articles