Accessing nested json object ngmodel

1,409 views
Skip to first unread message

David Duff

unread,
Mar 5, 2014, 4:47:30 PM3/5/14
to ang...@googlegroups.com
Hi,

I have a person object, which uses an Address object

"Person": {
     "Id": 1,
     "Forename": "Forename",
     "Surname": "Surname",
     "Address": {
        "Id": 1,
        "Line 1": "Line 1,
     }
}

I trying to access the data for the form where the person would update the details

<input type="text" name="addressLine1" data-ng-model="Person.Address[0].Line1" />

Doesn't work.  What am I doing wrong?  How should I be accessing "Line 1"?

Thanks in advance,
David

Chris Rhoden

unread,
Mar 5, 2014, 6:27:06 PM3/5/14
to ang...@googlegroups.com
David,

Address[0] doesn't refer to an object. Address is not an array - you should be using Person.Address['Line 1']

Further, you should be using keys without spaces in them.


--
You received this message because you are subscribed to the Google Groups "AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to angular+u...@googlegroups.com.
To post to this group, send email to ang...@googlegroups.com.
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/groups/opt_out.



--
chrisrhoden

David Duff

unread,
Mar 6, 2014, 6:40:37 PM3/6/14
to ang...@googlegroups.com
Thanks Chris, much appreciated.  It still isn't working but it has given a couple of ideas before asking any more questions.

Person displays [object object]
Person.Address <Blank>
Person.Address['Line1'] <Blank>

The json data returned from the web api get request has all the data.  Just can't access it just now.  Using postman to verify the get request works.
Reply all
Reply to author
Forward
0 new messages