I have an array containing the days of the week. It looks like this:
$scope.days=[{id:0, day: 'Monday'},{id:1, day: 'Tuesday'},{id:2, day: 'Wednesday'},{id:3, day: 'Thursday'}, {id:4, day: 'Friday'}, {id:5, day:'Saturday'}, {id:6, day:'Sunday'}];
and a user with a string containing the days he/she is available:
$scope.user={"userdays":"1011111"};;
1 = available, 0=unavailable.
I bind it to a list of checkboxes like this:
<p ng-repeat="day in days">
<input ng-model="userdays[day.id]" ng-checked="user.userdays[day.id]!=0" type="checkbox" />
{{day.day}}</p>
creating a list of checkboxes for the array of days and checking the days, the user is available.
Whenever a change occurs, I add the day to a property:
$scope.userdays={};
I would then like to save the days the user is available. But unless I make a change (ie click on one of the checkboxes), the $scope.userdays-property does not contain anything, and it only contains the value of the checkbox I have interacted with.
My question is, how do I get the values of all the checked checkboxes, regardless of whether I have actually clicked one of the checkboxes?
I have created a plunker here,showing my current implementation: http://plnkr.co/edit/Yrr2wrcoUno6tzgBgOMa?p=preview
thanks
Thomas