0
私にはデータを追加するためのフォームがあります。データ更新の場合も同じです。私は、$ http post経由で特定のIDに対してデータを取得することによってフォームにデータを埋め込みます。私はスコープ変数を変更しましたが、変更された値を取得しませんでした。ここに私の努力です:
<input type="hidden" name="form_type" ng-model="formData.formType" ng-init="formData.formType = submit_button" value="{{submit_button}}"/>
<input type="hidden" name="student_id" ng-model="formData.studentId" ng-init="formData.studentId = student_id" value="{{student_id}}"/>
$scope.Edit = function (id) {
$http({
method: 'POST',
url: 'process.php',
data: $.param({action: 'fetch', id: id}),
headers: {'Content-Type': 'application/x-www-form-urlencoded'}
}).success(function (response) {
if (!response.success) {
alert("something went wronge");
return false;
} else {
$scope.formData = response.data;
$scope.student_id = response.data.id;
$scope.submit_button = 'Update';
$scope.$apply();
}
});
};
この記事のトップの答えは役に立つかもしれ:http://stackoverflow.com/questions/22733422/angularjs-rootscopeinprog-inprogress-error – user95227
しかし、なぜあなたは 'を呼び出す必要があります$ scope。$ apply() '?ダイジェストサイクルが自動的に開始されますが、なぜ手動で開始するのですか? – iulian
@iulian隠しフィールドのスコープ変数を変更した後に、ポストデータの値が更新されないためです。 –