I can't seem to figure out this specific situation
Data:
$scope.MyItem = [
{
"__v": 0,
"myItemId": "55ed819caefe18e81ffbd2d2",
"itemId": "56fec8abb192c870117ed393",
"january": 1,
"february": 1,
"march": 1,
"april": 1,
"may": 1,
"june": 1,
"july": 1,
"august": 1,
"september": 1,
"october": 1,
"november": 1,
"december": 1,
"_id": "56fec8abb192c870117ed394",
"itemName": "apple"
},
{
"__v": 0,
"myItemId": "55ed819caefe18e81ffbd2d2",
"itemId": "56fec8bfb192c870117ed395",
"january": 1,
"february": 1,
"march": 1,
"april": 1,
"may": 1,
"june": 1,
"july": 1,
"august": 1,
"september": 1,
"october": 1,
"november": 1,
"december": 1,
"_id": "56fec8bfb192c870117ed396",
"itemName": "other"
}
];
myapp.monthName = [
{text: 'january'},
{text: 'february'},
{text: 'march'},
{text: 'april'},
{text: 'may'},
{text: 'june'},
{text: 'july'},
{text: 'august'},
{text: 'september'},
{text: 'october'},
{text: 'november'},
{text: 'december'}
];
Below is the table
<form class="form-inline" ng-submit="myapp.updateMyItems()" >
<tbody>
<tr ng-repeat="item in MyItem">
<td>
{{item.itemName}}
</td>
<td ng-repeat="monthName in myapp.monthName">
<input type="number"
ng-model="MyItem[item._id][monthName.text]"
value="{{item[monthName.text]}}"
>
</td>
</tr>
</tbody>
<button type="submit">Save</button>
</form>
The table shows 2 rows with 12 columns, each with a value of 1. Changing the first semester of the first row to 2 and the second row's last semester to 2 as well, upon form submission I receive the following object:
myapp.updateMyItems = function() {
var countryItem = $scope.countryItem;
console.log(countryItem); // output:
// [Object, Object, 56fec8abb192c870117ed394: Object, 56fec8bfb192c870117ed396: Object]
//
// where Object, Object have the same values as "$scope.MyItem" and
//
// 56fec8abb192c870117ed394 contains
// april : 2
// february : 2
// january : 2
// july : 1
// june : 2
// march : 2
// may : 2
// ... except for the last semester, with an exception in July having 1
// 56fec8bfb192c870117ed396 contains
// august : 2
// december : 2
// february : 1
// july : 2
// november : 2
// october : 2
// september : 2
// showcasing the reverse scenario from the previous object
};
These results are not as expected. Can anyone suggest what might be wrong here within Angularjs?