如何在angularJS中编辑时,如果DB中的值为true,则设置复选框,如果值为false,则取消选中复选框

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

本文关键字:如果 复选框 true false 设置 取消 DB angularJS 编辑      更新时间:2023-09-26

我正在尝试根据DB 1或0中的值自动设置复选框在我的控制器中返回true或false如何根据数据库中的值自动选中复选框。即,如果为true则选中,如果为false则取消选中这是angularJS代码

$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;
    });

这是复选框

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

我是新来的棱角分明,谢谢!!

试试这个:

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

$scope.box应为布尔值true/false,而不是字符串"true"/"false"

你可以检查工作中的jsfiddle

有关更多详细信息,请查看此处