0
我是AngularJS的初學者,我試圖從後端加載下拉列表到表單,並將選擇提交到後端。從後端加載下拉並在AngularJS中提交表單
這裏是形式NG-模型 'startApproval'
<form ng-controller="RequestController" ng-submit="request.startApproval()">
這裏是下拉選擇和loadApprover從服務器獲取對象 。
<select ng-model="request.approvalObject.approver1_email" ng-options="load as load.approver1_name for load in loadApprover()"></select>
表單提交
<input class="btn btn-info btn-lg col-xs-3" style="margin-left: 350px; margin-bottom: 50px" style="margin-bottom: 300px;" type="submit" value="request">
Request.controller.js
'use strict';
export default class RequestController {
approvalObject = {};
form = {};
secondApprover = false;
$onInit() {
this.approvalObject.generic_process_id=1;
this.approvalObject.value_currency="EUR";
this.approvalObject.priority=1;
this.form.type=1;
}
/*@ngInject*/
constructor($http, $scope, socket) {
this.$http = $http;
console.log("testentry");
}
loadApprover(){
$http.get('/api/approvals', approver1_name)
.success(function(data){
this.approver1_name=data;
return data;
})
}
startApproval(approvalObject) {
console.log(this.approvalObject);
this.approvalObject.approver1_email= this.approvalObject.approver1_name+"@example.com";
// wip from backend
this.approvalObject.approval_process_status= "wip";
this.approvalObject.priority= "super high";
//date_of_creation: '', -->> filled by database
this.approvalObject.sending_tool= "Web-App";
this.approvalObject.submitRequest=true;
this.$http.post('/api/approvals', this.approvalObject);
}
}
我不確定我犯了什麼錯誤,但我無法獲取數據。有人可以幫助我加強這個問題..