RESTfulなAPIとともに角度を使ってプレイヤーやチームの情報を表示、編集、削除できるシステムを作成しようとしています。私はすべてのデータを表示し、データをデータベースに投稿する部分を持っています。オブジェクト内のレコードを1つ更新して削除する
私が問題を抱えているのは、正しいデータが送信されている状態でhttp putを処理できないため、データを更新することです。
HTML
<script type="text/ng-template" id="team-single.html">
<div class="team-box">
<div class="badge">
<img ng-src="images/{{x.club_name}}.png" width="100" height="100"></div>
<div ng-hide="editorEnabled">
<div class="team-name">{{x.club_name}}</div>
<p><b>Manager:</b> {{x.club_manager}}</p>
<p><b>Ground:</b> {{x.club_ground}}</p>
<p><b>Nickname:</b> {{x.club_nickname}}</p>
<div class="team-p">{{x.club_info}}</div>
<a href="#" ng-click="editorEnabled=!editorEnabled">Edit Team</a>
</div>
<div ng-show="editorEnabled">
<p><input ng-model="x.club_name"></p>
<p><input ng-model="x.club_manager"></p>
<p><input ng-model="x.club_ground"></p>
<p> <input ng-model="x.club_nickname"></p>
<p><input ng-model="x.club_info"></p>
<input type="hidden" name="id" ng-value="" />
<a href="#" ng-click="editorEnabled=!editorEnabled; updateTeam($index)">Save</a>
</div>
</script>
<div class="row teams">
<div class="container">
<div class="col-md-4" ng-repeat="x in teams" ng-include="'team-single.html'"></div>
</div>
JS
var app = angular.module('footballApp', []);
app.controller("TeamCtrl", function ($scope, $http) {
$scope.updateTeam = function() {
$http({
method: 'PUT',
url: 'clubs.php/teams/' + id,
data: ??,
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
}
});
};
});
私はフィールドを編集するために、フロントエンドにエディタを有効にしています。チームアレイ全体を渡していないうちに、編集対象の1つのオブジェクトをupdateTeam関数に渡す方法がわかりません。
また、HTTP PUTでは、URLに関連するクラブのIDフィールドを使用する必要がありますが、これを返信する方法がわかりません。
ご協力いただければ幸いです。
<my-team-directive data="x"></my-team-directive>
ようにそれを含める場合://ドキュメントを。変更後に更新機能を開始するには、[$ watch](https://docs.angularjs.org/api/ng/type/$rootScope.Scope#$watch)モデルを変更した場合 –PUTはファイルまたはリソースを特定のURIに置きます。 POSTはデータを特定のURIに送信し、そのURIのリソースが要求を処理すると想定します。おそらくPOSTが必要です。 – tic