--
You received this message because you are subscribed to the Google Groups "AngularJS" group.
To view this discussion on the web visit https://groups.google.com/d/msg/angular/-/0HH231TmVvYJ.
To post to this group, send email to ang...@googlegroups.com.
To unsubscribe from this group, send email to angular+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/angular?hl=en.
--
ng:click
=
"function()" to update the model
items = [{id:1, title:'one'}, {id:2, title:'two'}, {id:3, title:'three'}];
selected = [1,3]
,which means checkbox for title "one" and "three" should be checked.
I think the only thing really needed would be to be able to attach two
methods to checkbox, something like:
ng:onChecked = "someMethodWhenSelected(p1,p2,...,pN)"
ng:onUnchecked = "anotherMethodWhenDeselected(p1,p2,...,pN)"
ng:isSelected = "isSelected(p1,p2,...,pN)"
So, instead of ng:bind, one would be able to invoke whatever code in
controller to handle selecting/deselecting.
Regards,
Witold Szczerba
> --
> You received this message because you are subscribed to the Google Groups
> "AngularJS" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/angular/-/7N0_G90M9FIJ.
The only thing I had to add to your sample was ng:checked, so it looks
like this now:
<div ng:repeat="item in items">
<input type="checkbox"
ng:model="s"
ng:change="toggle(item.id, s)"
ng:checked="{{ isSelected(item.id) }}">
</div>
Working example, applied to ProLoser's example:
http://jsfiddle.net/witoldsz/efkAY/11/
Thanks,
Witold Szczerba
<input type="checkbox" ng:model="v"
ng:change="toggleSelected(color.name, v)"
ng:checked="{{isSelected(color.name)}}">
The model "_v" does not gets initialized properly, it is always
null/false/undefined, look at the snippet below:
http://jsfiddle.net/witoldsz/efkAY/14/
As you can see above, two first checkboxes are checked, but theirs
model are incorrect, try deselecting them and see there are no updates
in the model.
The correct way is to use ng:init instead of ng:checked:
http://jsfiddle.net/witoldsz/efkAY/15/
<input type="checkbox" ng:model="v"
ng:change="toggleSelected(color.name, v)"
ng:checked="v = isSelected(color.name)">
Now model (v) gets initialized correctly and there is no de-sync
between "checked" and model value.
Regards,
Witold Szczerba
The correct way is to use ng:init instead of ng:checked:
http://jsfiddle.net/witoldsz/efkAY/15/
<li ng:repeat="color in colors">
{{color.name}}
<input type="checkbox" ng:model="v"
ng:change="toggleSelected(color.name, v)"
ng:init="v = isSelected(color.name)">
</li>
The key here is the "ng:init: which initializes the "v" model for the
scope of each list item.
Regards,
Witold Szczerba