Here is a simplified example of what I'm trying to do.
(function(){
var app=angular.module('Tester',[]);
app.controller('TestController',function($scope){
$scope.days=[{name:'Sun'},{name:'Mon'},{name:'Teu'},{name:'Wed'},{name:'Thu'},{name:'Fri'},{name:'Sat'}];
//if I is use `days=['Sun','Mon'...]` it works
$scope.values={};
$scope.add=function(values){
var sum=0;
$scope.days.map(function(v){
v=values[v];
if(v){
sum+=(v-0);
}
});
return sum;
}
});
app.filter('sum',function(){
return function(obj){
var total=0;
for(var v in obj){
total+=(obj[v]-0)||0;
}
return total;
}
});
})()
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="Tester">
<div ng-controller="TestController as test">
<input ng-model="values[day.name]" value="{{values[day.name]||0}}" ng-repeat="day in days">
<div>{{add(values)}}</div>
<div>{{values | sum}}</div>
</div>
</div>
Basically I want to have a row of inputs and a total to show the sum. It works if I use days=['Sun','Mon'...] or a filter. But the filter seems semantically incorrect as well as not allowing me to add other properties to the values object (value={'Mon':2,'time':123456789} would give an incorrect sum) and days=[{name:'Sun'}...] allows me to store more information than days=['Sun','Mon'...] about each day.
addas well?value={'Mon':2,'time':123456789}