for some reason I cannot get the below 2 way binded. I'm trying to make a dynamic way of filling the ng-model in forms
html:
<thead ng-repeat="field in fields">
<tr>
<th>
<select ng-model="{{field.day}}"></select>
</th>
<th>
<select ng-model="{{field.month}}"></select>
</th>
<th>
<select ng-model="{{field.morning}}"></select>
</th>
<th>
<select ng-model="{{field.eveningOpen}}"></select>
</th>
<th>
<select ng-model="{{field.eveningClosing}}"></select>
</th>
<th>
<input type="checkbox" ng-model="{{field.checkMorning}}" />
</th>
<th>
<input type="checkbox" ng-model="{{field.checkEvening}}" />
</th>
</tr>
</thead>
</table>
<!-- add extra field -->
<button class="btn" ng-click="addNew()"c>add extra field</button>
<!-- delete last field -->
<button ng-show="fields.length > 0" class="btn" ng-click="deleteLast()"c>remove last extra field</button>
and here the angular/javascript:
$scope.fields = [];
$scope.addNew = function() {
var newItemNo = $scope.fields.length+1;
$scope.fields.push(
{
'day' :'day'+newItemNo,
'month' : 'month'+newItemNo,
'morning' : 'morning'+newItemNo,
'eveningOpen' : 'eveningOpen'+newItemNo,
'eveningClosing' : 'eveningClosing'+newItemNo,
'checkMorning' : 'checkMorning'+newItemNo,
'checkEvening' : 'checkEvening'+newItemNo
}
);
console.log($scope.fields);
};
$scope.deleteLast = function() {
$scope.fields.pop();
}
am I missing some limitation because everyone who did it this way on stack was successfull :/