So I have a Controller with multiple tasklist models in my scope. Something like this.
$scope.taskslists = [
{
id : 1,
percentCompleted : 0,
tasks : [
{
completed : false,
description : 'Lorem ipsum dolor sit amet,'
},
{
completed : false,
description : 'consectetur adipisicing elit, sed do eiusmod'
},
]
},
{
id : 2,
percentCompleted : 0,
tasks : [
{
completed : false,
description : 'Lorem ipsum dolor sit amet,'
},
{
completed : false,
description : 'consectetur adipisicing elit, sed do eiusmod'
},
]
},
];
For each tasklist when a completed value of a task is changed to true or false, i want to update the percentCompleted attribute in my corresponding tasklist model. I was looking at using $watch to accomplish this.
$scope.$watch('tasklists', function(newValue, oldValue){
//Calculate percent completed.
console.log(newValue);
}, true);
While it fires fine it always returns the entire collection, but I am only interested in the tasklist that got updated out of that collection. I understand that this is an expensive task so I am wondering if there is a way I can be more selective about the values I am listening for and updating. I am pretty new to Angular so I am not sure if this might be the wrong approach all together.
My only goal is to display a progress bar that takes its width from the percent of completed tasks.
<div ng-repeat="tasklist in tasklists" >
<div class="progress-bar" style="width: {{tasklist.percent.completed}}%;"></div>
<ul class="list-unstyled task-list">
<li ng-repeat="task in tasklist.tasks">
<input ng-model="task.completed" type="checkbox">
<span>{{task.description}}</span>
</li>
</ul>
</div>