LL Janneh LL Janneh - 2 years ago 106
AngularJS Question

how to set a checkbox if the value from the DB is true and uncheck if the value is false on edit in angularJS

I am trying to auto set a checkbox base on the value in the DB 1 or 0
which is returning true or false in my controller
how can I auto check a checkbox base on the value from the DB . i.e check if true and uncheck if false
this is the angularJS code

$http.get('/api/cusEmoAllo/' + $routeParams.EmpID).success(function (data)
//data[0].taxS); this may true or false // check if true uncheck if false
$scope.box = data[0].taxS;

this is the checkbox

<input id="box" type="checkbox" ng-model="box" />

I am new in angular, thanks!!

p2. p2.
Answer Source

Try this :

<input id="box" type="checkbox" ng-model="box">

$scope.box should be boolean true/false , not String "true"/"false"

you can check the working jsfiddle

For more details check here

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download