Issue
Is there a way to pass to angular directive ng-click the value of the associated input?
In other words, what should replace this.value
in the following:
<input type="checkbox" id="cb1" ng-click="checkAll(this.value)" />
PS. I don’t want a workaround to alternate values, I just wonder if is possible to pass a value of an input as argument to an angular function.
Solution
You can do the following things:
- Use ng-model if you want to bind a html component to angular scope
- Change
ng-click
tong-change
- If you have to bind some value upon checking and un-checking the checkbox use
ng-true-value="someValue"
andng-false-value="someValue"
The order of execution of
ng-click
andng-model
is ambiguous since
they do not define clear priorities. Instead you should use ng-change
or a$watch
on the$scope
to ensure that you obtain the correct values
of the model variable.
Courtesy of musically_ut
<input type="checkbox" id="cb1" ng-model="check" ng-change="checkAll(check)" ng-true-value="YES" ng-false-value="NO"/> Citizen
Answered By – Nidhish Krishnan
Answer Checked By – Marilyn (AngularFixing Volunteer)