Pallavi Pallavi - 7 months ago 123
PHP Question

How to show checkbox checked if data is saved in database using "AngularJS"?

I am working with

SugarCRM
API for
get_module_fields
and displaying its results in Checkbox You can check here . I have saved some checkbox value in database using
AngularJS
checklist-model
and now I want to update it.So for that I want to display saved checkbox as checked but I unable to do that.Is any one can tell me how to do that?
here is my script code and i dont know what to write in
$scope.users.mod_fields
so that i can display checked checkbox



<script>
var app = angular.module("myApp", ["checklist-model"]);
app.controller('myCtrl', function($scope,$http) {
$scope.users = {};
$scope.users.mod_name = '<?php echo $module_name;?>';
$scope.users.mod_id = '<?php echo $module_id;?>';
$scope.users.mod_fields ='';
$scope.updateModule=function(){
$http.post("update_modulelist.php", {'mod_id':$scope.users.mod_id,'mod_name':$scope.users.mod_name, 'mod_fields' : $scope.users.mod_fields})
.success(function(data,status,headers,config){
alert(JSON.stringify(data));
//alert("Data Inserted Successfully");
window.location.href="show_modulelist.php";
});
}
});
</script>




Answer

Done like this & got perfect answer:

var app = angular.module("myApp", ["checklist-model"]);
app.controller('myCtrl', function($scope,$http) {
	$scope.users = {
		mod_fields: '<?php foreach ($items as $key=>$val) { echo $val.',';}?>'
	};
	$scope.users.mod_name = '<?php echo $module_name;?>';
	$scope.users.mod_id = '<?php echo $module_id;?>';
	$scope.users.mod_fields =  <?php
                    $module_fields = $_GET['fields']; 
					$module_fie =explode(',',$module_fields);
					json_encode($module_fie);
                    echo json_encode($module_fie) ?>;
	$scope.updateModule=function(users){		
				$http.post("update_modulelist.php", {'mod_id':$scope.users.mod_id,'mod_name':$scope.users.mod_name,  'mod_fields' : $scope.users.mod_fields})
				.success(function(data,status,headers,config){
						window.location.href="show_modulelist.php";
				});
			}
});

Comments