How do I sync 2 objects based on the change of a checkbox?

Viewed 1158

I'm at the very beginning stage of learning Angularjs, so please bear with me for asking this stupid question. I basically want to do it the right way from the start instead of just making it work.

Anyhow, I have 1 Order Checkout form which contains 2 sets of addresses: shipping and billing. I have a checkbox which says "Shipping address is the same as billing address", which if checked should sync the 2 addresses.

My approach is that 2 addresses will be treated as 2 objects, and if the checkbox is checked then I will have something like scope.shippingAddress = scope.billingAddress.

I wonder if the above is a good way to do it?

Also, what is a good way to trigger the above syncing upon checkbox change? Should I use ng-checked or perhaps should I use $watch?

1 Answers
Related