私の仕事のためにUpdateメソッドを作成する必要がありますが、AngularJsではフォームがng-model情報を取得していないので、どうしてか分かりません。 2時間前に私は簡単なPOSTメソッドで簡単にやっていたからです。ここでPUTメソッドはAngularJsで機能しません
は私のコントローラのコードです:
$scope.UpdateData = function (petId) {
$http({
method: 'PUT',
url: baseApiUrl + '/pets/' + petId,
data: {
id: petId,
name: $scope.updateName,
age: $scope.updateAge,
owner: $scope.updateOwner,
}
}).then(function successCallback(response) {
console.log(response);
}, function errorCallback(response) {
console.log(response);
});
};
そして、これが私の見解である:私は私のフォームの値を変更すると
<table class="table table-hover table-bordered">
<thead>
<tr class="text-center pointer back-grey">
<th class="text-red">
Nom
</th>
<th class="text-red">
Age
</th>
<th class="text-red">
Propriétaire
</th>
<th class="text-red">
Action
</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="pet in pets">
<td><input type="text" placeholder="{{ pet.name }}" name="name" class="form-control" ng-model="updateName" required></td>
<td><input type="text" placeholder="{{ pet.age }}" name="age" class="form-control" ng-model="updateAge" required></td>
<td><input type="text" placeholder="{{ pet.owner }}" name="owner" class="form-control" ng-model="updateOwner" required></td>
<td><input id="update" type="submit" class="btn btn-danger disabled" ng-click="UpdateData(pet.id)" /></td>
</tr>
</tbody>
</table>
、と私はこれを持っているボタンを押します。
をObject {data: "1", status: 200, config: Object, headers: function}
私が尋ねたとおり、IDは尋ねられますが、名前は変更されません。そして、私が$ helloのような文字列で$ scope.updateNameを変更すると、これは動作しています...
ありがとうございました!
プロパティ「0」未定義のを設定することはできません。 –
あなたは配列をinitiliazeしていないようです。スコープのinitilizationでこれを行う必要があります:** $ scope.updateAge = []; **したがって、すべての配列に対してそうです。 – Vanderson