I want to get some attr's value in a checkbox when it is checked,is there any directive for it?
Asked
Active
Viewed 36 times
-1
-
you can refer this http://stackoverflow.com/questions/36996145/checkbox-directive-in-angular/36996405#36996405 – byteC0de May 05 '16 at 05:05
-
why use a directive just for it? haha there is no need – Diego Polido Santana May 05 '16 at 05:08
-
you can achieve that by injecting `$attrs` into the controller, refer this answer for more clarity, http://stackoverflow.com/a/29485941/1677272 – dreamweiver May 05 '16 at 05:47
-
sorry everyone.... I forget say that they are multi checkbox produced by ng-repeat . is there any great way or useful directive? – Potato Running May 05 '16 at 08:55
2 Answers
1
use the native ng-model
:
<input type="checkbox" ng-model="valid"/>
and in your controller:
$scope.valid //true or false

Diego Polido Santana
- 1,425
- 11
- 19
0
The attributes are ng-true-value
and ng-false-value
.
<input type="checkbox" ng-model="box" ng-true-value="'yes'" ng-false-value="'no'">
In the above example the variable $scope.box
will be set to 'yes'
when the box is checked; 'no'
when unchecked.
For more information, see AngularJS input[checkbox] Directive API Reference.

georgeawg
- 48,608
- 13
- 72
- 95