Just starting out with Angular so bear with me :)
I'm working on a page that displays a list of items from a JSON object. This JSON object contains an array of dates.
$obj = [
{
id: '1',
GoalName: 'Drink More Water',
StartDate: '9/1/2015',
EndDate: '9/30/2015',
GoalType: "positive",
Category: "Health",
Weight: "3",
TimesPerWeek: 4,
Dates: {
"09/11/2015": 0,
"09/10/2015": 1,
"09/08/2015": 1
}
}
I've managed to use ng-repeat to display the items from the array, but I'm struggling with controlling the checkboxes. What I want to do is display a date on the screen and then check if that date is present in the array, and if it is, mark the checkbox as checked. Additionally, when a user clicks the checkbox, it should update the item. I know I need to create a model for the checkboxes, but I'm not completely sure how to go about doing that.
app.controller('TrackGoals', function ($scope) {
$scope.today = Date.today();
});
<ul class="list" id="thehabits" ng-repeat="goal in goals">
<li class="expanded-cell">
<div class="pull-right form-group cell-content">
<label>
<input type="checkbox" class="option-input checkbox" ng-model="ids[goal.dates.id].value">
</label>
</div>
<div class="cell-content">
<span id="habittext" class="title">{{ goal.GoalName }} </span>
</div>
</li>
</ul>