LL Janneh LL Janneh - 1 year ago 80
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