问题描述
我工作的平均堆污物和我接近有它功能全面,但我坚持试图从表单字段的实际数据来拉。我现在有数组值硬$ C $光盘,里面的作品,但我想用输入的表单字段的值替换编辑。
I'm working on a mean stack crud and am close having it fully functional but am stuck trying to pull in the actual data from the form fields. I currently have the array values hard coded, which works but I'd like to replace the 'edited' with the entered form field values.
我的角度PUT请求:
$scope.editService = function(id) {
$http.put('/api/hc/' + id,
{title: 'edited',
shortname: 'edited',
summary: 'edited',
description: 'edited'}
)
.success(function(data) {
})
.error(function(data) {
console.log('Error: ' + data);
});
};
我的角形式:
<form name="editForm" ng-submit="editService(service._id)" ng-repeat="service in services | filter:json">
<input type="text" placeholder="{{ service.title}}" ng-model="serviceTitle" required>
<input type="text" placeholder="{{ service.shortname}}" ng-model="serviceShortname" required>
<input type="text" placeholder="{{ service.description}}" ng-model="serviceSummary" required>
<textarea type="text" placeholder="{{ service.summary}}" ng-model="serviceDescription" required></textarea>
<button type="submit">Edit</button>
</form>
我最初的想法是,以取代$ scope.serviceTitle的'编辑'值,但似乎并没有工作。有效载荷返回空。
My initial idea was to replace the 'edited' values with $scope.serviceTitle but that doesn't seem to work. The payload returns empty.
推荐答案
我觉得下面是做正确的方式,它的我的假设您正在填充$ scope.service在一些previous code。请注意,我删除占位符,并用$ scope.service为NG-模型变量。
I think below is the right way to do it, its my assumption you are populating $scope.service in some previous code. Notice I remove place holder, and used $scope.service as ng-model variable.
$scope.submit = function() {
$http.put('/api/hc/' + $scope.service.id, $scope.service)
.success(function(data) {
})
.error(function(data) {
console.log('Error: ' + data);
});
};
<form name="editForm" ng-submit="submit()" ng-repeat="service in services | filter:json">
<input type="text" ng-model="service.title" required>
<input type="text" ng-model="service.shortname" required>
<input type="text" ng-model="service.description" required>
<textarea type="text" ng-model="service.summary" required></textarea>
<button type="submit">Edit</button>
</form>
这篇关于角传球$范围数据导入PUT请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!