0
[  
   {  
      "id":1,
      "name":"Ashiz",
      "email":"[email protected]",
      "message":"How are you yankee\r\n",
      "created_at":"2017-05-24 03:16:53",
      "updated_at":"2017-05-24 03:16:53"
   }
]
.map(res => res.json());

While i use json data, in above way, than it works fine . That i can use json data but when i use this way as object only than i got error. why? what is the differences between square bracket and without square bracket how to work with this?

{  
   "id":1,
   "name":"Ashiz",
   "email":"[email protected]",
   "message":"How are you yankee\r\n",
   "created_at":"2017-05-24 03:16:53",
   "updated_at":"2017-05-24 03:16:53"
}
2
  • 2
    [] is an array or an iterable and {} is an object with key-value pairs. ngFor needs an iterable.. Commented May 24, 2017 at 12:39
  • If you have just one object, you don't need *ngFor, you can just show the properties with e.g {{objectNameHere?.name}} notice the safe navigation operator: angular.io/docs/ts/latest/guide/… Commented May 24, 2017 at 13:09

1 Answer 1

1

When you are not using [] the you need to parse it with $.parseJSON like below.

jQuery.parseJSON({  
   "id":1,
   "name":"Ashiz",
   "email":"[email protected]",
   "message":"How are you yankee\r\n",
   "created_at":"2017-05-24 03:16:53",
   "updated_at":"2017-05-24 03:16:53"
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.