Im trying to implement an update form but when I click on the submit button, I have constantly this error :
TypeError: Cannot read property '1' of undefined
Here is my controller :
$scope.pets = [];
$http.get(baseApiUrl + '/pets').
success(function (data) {
console.log("Success : " + data);
$scope.pets = data;
}).error(function () {
console.log(data);
});
$scope.UpdateData = function (index) {
$http({
method: 'PUT',
url: baseApiUrl + '/pets/' + index,
data: {
id: index,
name: $scope.updateName[index],
age: $scope.updateAge[index],
owner: $scope.updateOwner[index],
}
}).then(function successCallback(response) {
console.log(response);
}, function errorCallback(response) {
console.log(response);
});
};
And this is my view :
<tbody>
<tr ng-repeat="pet in pets track by pet.id">
<td><input type="text" placeholder="{{ pet.name }}" name="name" class="form-control" ng-model="updateName[pet.id]" required></td>
<td><input type="text" placeholder="{{ pet.age }}" name="age" class="form-control" ng-model="updateAge[pet.id]" required></td>
<td><input type="text" placeholder="{{ pet.owner }}" name="owner" class="form-control" ng-model="updateOwner[pet.id]" required></td>
<td><input id="update" type="submit" class="btn btn-danger disabled" ng-click="UpdateData(pet.id)" /></td>
</tr>
</tbody>
I can't find why this is not working. If you have any suggestion. Thanks