0
このフォームをいくつかのWebサービスに投稿しています。ここで約束データからフォーム入力値を設定する
<form name="myForm" id="myForm" method="post" action="https://servicelink.....etc" accept-charset="utf-8">
<input type="hidden" name="accepturl" value="{{$ctrl.accepturl}}" ng-model="$ctrl.accepturl">
<input type="hidden" name="callbackurl" value="{{$ctrl.callbackurl}}" ng-model="$ctrl.callbackurl">
<input type="hidden" name="orderid" value="{{$ctrl.orderid}}" ng-model="$ctrl.orderid">
</form>
私の角度コントローラされています(私はコンポーネントとAngularJS 1.5.8を使用しています)
function controller(someservice) {
var ctrl = this;
ctrl.accepturl = $window.location.href;
ctrl.callbackurl = "https://........";
ctrl.placeOrder = function() {
someservice.placeOrder(ctrl.amount).then(onOrderInitiation, onOrderInitiationError);
}; //$http.post call is made there
function onOrderInitiation(data) {
ctrl.orderid = data;
// I tried to set the input value by javascript as well with no success
// document.getElementsByName('orderid').value = data;
document.getElementById("flexwinSubmit").submit();
}
}
ここでは$ http.postが行われているサービスです。
this.placeOrder = function(amount){
return $http.post("/rest/.........)
.then(function(response){
return response.data.orderId;
});
};
だから、私はhtmlのorderid入力値を約束関数データ(onOrderInitiation)から更新してからフォームを送信しなければなりません。しかし、私はそれをどんな手段でも更新することはできませんでした。しかし、ctrl.orderidが正しく設定されています(ログで確認しました)。
JavaScriptの設定をしようとすると、値が正しく変更されます。しかし、フォームを送信するとき、値は設定されません。
document.getElementsByName('orderid').value = data;
可能な重複http://stackoverflow.com/questions/14220321/how-do-i-return-the-response-from-an -asynchronous-call) – baao
ng-value = "ctrl.orderid" – GraveyardQueen
@GraveyardQueenそれは何の違いもありません:(ブラウザでそれを調べると面白いことです値は設定されていますが、フォームを送信するときには設定されません!! – Hazu