When displaying amenity checkbox options using ng-repeat of a JSON array and saving them into the database as comma-separated IDs like "1,3,7" within a single string, the challenge arises when needing to edit the amenities. This is due to retrieving the existing values from the database as "1,3,7" within a single string format. How can this string be compared to the options in the ng-repeat to display the existing values as checked?
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"></script>
<script>
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope) {
$scope.amenities=[{id:1,value:"Wifi"},
{id:2,value:"AC"},
{id:3,value:"Creditcard"},
{id:4,value:"24x7"},
{id:5,value:"Parking"},
{id:6,value:"Free delivery"},
{id:7,value:"No Smoking"}
];
//Assuming this is an example of existing amenities from the database
$scope.existamenities="1,3,7";
});
</script>
<html>
<div ng-app="myApp" ng-controller="myCtrl">
<div ng-repeat="amn in amenities">
<label>{{amn.value}}
<input type="checkbox" name="amenities" ng-value="amn.id">
</label>
</div>
</div>
</html>