Search code examples
angularjsnestedangularjs-ng-repeat

Retrieve data from input on nested array


I have a nested array that I get the data from server and I want to PUT new data from SELECT box to server. My object data is binding correctly but the nested part doesn't. It stick with the original data no matter of what I entered in the select input.

HTML:

<div class="AL_box" ng-repeat="alarm in alarms">


<li>Alarm {{$index}} </li> <li>
<li>
    <button type="button" class="ok_button" ng-click="alarmsClk(alarm, $index)">Ok</button>
</li>
<br>
<h2>Setpoint: </h2><br>
<div class="sp_box" ng-repeat="setpoint in alarm.setpoints track by $index">
    <li>#{{$index}}<input class="setpoint" type="number" name="#ch" min="5" max="35" step="0.5" ng-model="setpoint"></li>
</div>

JS

$scope.alarmsClk = function($scope, index) {
    var chanObj = { index : index, data : $scope };
    console.log(chanObj)
    service.putAlarms(chanObj, function() {});
}

return JSON

data: {switch: "Off", type: "tuesday", hour: 3, minute: 0,…}
hour: 3
minute: 0
setpoints: [21, 21, 21, 21, 21, 21, 21, 21, 21, 21]
switch: "Off"
type: "tuesday"
index: 0

The setpoints never bind.


Solution

  • Try this

    <input class="setpoint" type="number" name="#ch" min="5" max="35" step="0.5" ng-model="alarm.setpoints[$index]">
    

    JSFiddle