JSON object not getting updated

671 views
Skip to first unread message

Bhushan N.N

unread,
Feb 18, 2013, 12:53:04 PM2/18/13
to ang...@googlegroups.com
Hi,

I am trying to update a JSON object but it's not happening. What am I doing wrong here?

Please take a look at my jsbin at http://jsbin.com/otovum/2

When you click on true, it should turn to false. This is happening on the view but not in the json object

Thank you
Bhushan

Bhushan N.N

unread,
Feb 18, 2013, 1:01:05 PM2/18/13
to ang...@googlegroups.com

Clint Checketts

unread,
Feb 18, 2013, 2:22:37 PM2/18/13
to ang...@googlegroups.com
I'm not sure what you mean by 'not updating the JSON object'


If I write out the model and pipe it to a json filter it is updating.


--
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?hl=en-US.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Jurgen Van de Moere

unread,
Feb 18, 2013, 5:19:58 PM2/18/13
to ang...@googlegroups.com
As far as I can see, the scope is getting updated correctly and the array in the scope is updated.

Or are you implying something else?



Op maandag 18 februari 2013 18:53:04 UTC+1 schreef Bhushan N.N het volgende:

Bhushan N.N

unread,
Feb 18, 2013, 8:44:53 PM2/18/13
to ang...@googlegroups.com
Hi Clint,

Thanks a lot. So if I want to save the content back, should I put the seats|json value to a hidden field and write that content back?

I was kind of expecting some 2 way data binding magic where the json object in the javascript file gets updated when I change the true to false value in the view.

Thank you
Bhushan

Jurgen Van de Moere

unread,
Feb 18, 2013, 8:57:02 PM2/18/13
to ang...@googlegroups.com
Hi Bhushan,

You have defined a scope with a variable that has a javascript array assigned to it (defined in your controller).

When you update the model with the ng-click handler, the variable in the scope is updated correctly.

So everything is working as expected in terms of AngularJS (as Clint pointed out by dumping the output of the seats).

What else are you expecting your code to do ? What exactly do you mean by updating 'the JSON object' ?

Thanks!

Regards,
Jurgen



Op dinsdag 19 februari 2013 02:44:53 UTC+1 schreef Bhushan N.N het volgende:

Bhushan N.N

unread,
Feb 18, 2013, 9:05:52 PM2/18/13
to ang...@googlegroups.com
Hi Jurgen,

I am a newbie and took all the tutorials on the AngularJS site. Maybe I am confused with this 2 way binding from view to the javascript. So I was expecting when the view changes, the same object in the javascript array to get updated as well. And I was wrong.

Thank you
Bhushan

Jurgen Van de Moere

unread,
Feb 18, 2013, 9:08:39 PM2/18/13
to ang...@googlegroups.com
Hi Bhushan,

No, you are not wrong. When you click the item, the two way binding is updating your model in the scope correctly.

So what you are expecting is actually happening.

If you open http://jsbin.com/otovum/7/edit and click on the list items, then you will see that the output of the model is updating.

Don't you see it updating ?

Regards,
Jurgen



Op dinsdag 19 februari 2013 03:05:52 UTC+1 schreef Bhushan N.N het volgende:

Clint Checketts

unread,
Feb 18, 2013, 10:31:37 PM2/18/13
to ang...@googlegroups.com
Bhushan,

I updated it so clicking on the seat now toggles the value: http://jsbin.com/otovum/9/edit (I also removed the extra div)

Notice how as you click the seat the value the json below toggles back and forth.  Since the value stored in the $scope (the model) is the source of truth, you could take it and just send that object (if you were trying to submit it to a server).

I included a save button to illustrate that in the jsbin example. The post method fails obviously, since jsbin isn't expecting it but you can see in firebug or devtools the request and the altered json being sent.




Reply all
Reply to author
Forward
0 new messages