ng-checked and ng-model

5,552 views
Skip to first unread message

floydsoft

unread,
Sep 20, 2012, 12:13:18 AM9/20/12
to ang...@googlegroups.com
Hi folks,

Current ng-checked is an one-way binding, and ng-model is a two-way binding, so we can assign ng-checked another model to effect the input, but input not effect another model.

This design can implement master-slave relationship to form group check, but ng-checked only effects input, it does't syncs ng-model, it's weird.

Consider http://jsfiddle.net/nAjXd/ , slave's model will not change even input is checked by ng-checked.

Since ng-model is two-way binding, input should honor this contract, so after ng-checked checks on input, it should checks ng-model too.

It may look like:

"master's model" (by ng-checked) --> input <--> "slave's model(ng-model)"

Current version will break when ng-checked checks input, ng-model will not be sync.

I've opened a PR https://github.com/angular/angular.js/pull/1057 , but Angular team didn't think it's make sense.

Do I make any mistake or other better solutions on this issue?

Peter Bacon Darwin

unread,
Sep 22, 2012, 3:37:06 PM9/22/12
to ang...@googlegroups.com
I would simply implement this in a different way:  http://jsfiddle.net/vdapp/ 

--
You received this message because you are subscribed to the Google Groups "AngularJS" group.
To post to this group, send email to ang...@googlegroups.com.
To unsubscribe from this group, send email to angular+u...@googlegroups.com.
Visit this group at http://groups.google.com/group/angular?hl=en.
 
 

Peter Bacon Darwin

unread,
Sep 22, 2012, 3:39:05 PM9/22/12
to ang...@googlegroups.com
Actually this doesn't quite work as I wanted...

Steve Ansell

unread,
Apr 23, 2014, 6:37:25 PM4/23/14
to ang...@googlegroups.com
The only way I've been able to get it to work is to have an ngScope assigned to the master checkbox and then update that scope variable as a side effect of the ngChecked call. This doesn't really seem kosher nor does it seem like it should be necessary (I expected Angular to handle this). Unfortunately, since I want to keep all of the logic in the master checkbox, this was the cleanest way.

Here's an update to your original fiddle (I use ngChange to update the child states rather than ngClick): http://jsfiddle.net/thr3ee/83cvu/

prathap kumar

unread,
Jan 28, 2015, 9:22:54 AM1/28/15
to ang...@googlegroups.com
I think you are correct

Reply all
Reply to author
Forward
0 new messages