I have already asked this question, but the previous solutions did not resolve my issue.
I am attempting to pass the value of a checkbox to a controller in AngularJS, but I keep getting an 'undefined' message. I am new to AngularJS.
Here is the HTML code snippet:
<form class="form-horizontal" name="addForm" novalidate ng-submit="addData(addForm)">
<div class="form-group">
<div class="col-sm-3" ng-repeat="directories in formData.getMainDirectories">
<input type="checkbox" ng-model="directories.main_directories_id.selected" value="{{directories.id}}"><span> {{directories.name}}</span>
</div>
</div>
<button type="submit" class="btn btn-primary btn-md" button-spinner="loading" ng-disabled="loading">Submit</button>
</form>
And here is the corresponding JavaScript code:
$scope.addData = function(form)
{
$scope.errors = [];
alert(form.main_directories_id); // alert included
if(form.$valid)
{
$rootScope.loading = true;
webServices.upload('create', $scope.formData).then(function(getData) {
$rootScope.loading = false;
if (getData.status == 200) {
$sessionStorage.successmessage = getData.data.message;
localStorage.directory = '';
$scope.goback();
} else if (getData.status == 401) {
$scope.errors = utility.getError(getData.data.message);
$scope.showerrors();
} else {
$rootScope.$emit("showerror", getData);
}
});
}
}
$scope.getMainDirectories = function()
{
webServices.get('getMainDirectories').then(function(getData)
{
$rootScope.loading = false;
if (getData.status == 200)
{
$scope.formData.getMainDirectories = getData.data;
} else {
$rootScope.$emit("showerror", getData);
}
//console.log(getData.data);
});
}