如何在angularjs中将表单数据保存到数据库
我是个新手。 我正在开发一个内部工具,在那里我可以获得用户的详细信息,如位置、工作档案和手机号码等。 所以我有一个带有位置、工作档案下拉列表和手机号码输入字段的表单。对于以上字段,我已经通过ajax get请求从数据库中获取了数据。如果我想更改mobileNumber之类的数据,我该如何做,以及如何将其保存到数据库中,该数据库应覆盖之前的手机号码。提前谢谢 以下是我的html代码:如何在angularjs中将表单数据保存到数据库,angularjs,ajaxform,Angularjs,Ajaxform,我是个新手。 我正在开发一个内部工具,在那里我可以获得用户的详细信息,如位置、工作档案和手机号码等。 所以我有一个带有位置、工作档案下拉列表和手机号码输入字段的表单。对于以上字段,我已经通过ajax get请求从数据库中获取了数据。如果我想更改mobileNumber之类的数据,我该如何做,以及如何将其保存到数据库中,该数据库应覆盖之前的手机号码。提前谢谢 以下是我的html代码: <form name="userForm"> <div
<form name="userForm">
<div class="page-heading fs-xs-1-5">
Update Profile
</div>
<div class= "second-row">
<div class="row">
<div class="col-lg-4">
<label for="Location"> Location</label>
<select class="form-control" placeholder="location" ng-model="user.location" required>
<option value="">Select Location</option>
<option>Hyderabad</option>
<option>Ahmadabad</option>
<option>New Jersey</option>
<option>California</option>
<option>Jaipur</option>
</select>
</div>
<div class="col-lg-4">
<label for="WorkProfile"> Work Profile</label>
<select class="form-control" placeholder="workprofile" ng-model="user.workProfile" required>
<option value="">Select Profile</option>
<option>UI Developer</option>
<option>Tester</option>
</select>
</div>
<div class="col-lg-4">
<label for="ContactNumber"> Contact Number</label>
<input class="form-width contact-height" type="text" ng-model="user.mobileNumber" maxlength="20" required></input>
</div>
</div>
</div>
<div class="third-row">
<div class="row">
<div class="col-lg-4">
<label for="SkillSet"> Skill Set</label>
<textarea id="SkillSet" class="form-width" placeholder="Enter Your skill set here..." row="4" col="100" ng-model="user.skillset" maxlength="250" required></textarea>
</div>
</div>
</div>
<button class="btn btn-primary setng-btn" type="submit" ng-click="addnewdata">Save</button>
</form>
这将是太多了,不清楚。 简而言之,您需要REST服务作为后端来调用以保存数据
AngularJS项目只是前端,您需要后端(使用Nodejs、JSP或asp.net/C#开发)来实现此目的。您向后端发送PUT请求,其中包含需要更改的数据,后端更新数据库。提交按钮上的需要调用函数
addnewdata()
,不只是命名函数。实际上我们在这里使用一个api,所以我需要将数据发布到该api,在后端api将把最新的数据保存到数据库中。但是在这里我不能将数据发布到api,你能帮我吗。提前谢谢。
(function () {
angular
.module('app.login')
.factory('userprofileService', userprofileService);
userprofileService.$inject = ['config', '$http'];
function userprofileService (config, $http) {
var userprofileService = this;
userprofileService.getUserDetails = function(){
return $http({
method: 'GET',
url: config.apiURL+'/v2/user',
headers: { 'Content-Type': 'application/json' }
}).then(function(response){
return response.data;
});
}
`