我从服务器收到请求。之后,当我点击toggle_edit()时,数据内容应该被编辑,当我点击toggle_save()时,编辑的内容应该被保存,它应该在json服务器中更新。但是当我点击保存按钮时,它会生成405错误和方法不允许。
Html代码:
<div ng-show="contact" id="contacts_edit()">
<div>
<button class="btn btn-secondary" ng-hide="editMode" ng-click="toggle_edit()"> Edit </button>
<button class="btn btn-success" ng-show="editMode" ng-click="toggle_save(cts.selectedcontact)"> Save </button>
</div>
<b> Street:</b>
<p ng-hide="editMode">
{{cts.selectedcontact.location.street}}
</p>
<input type="text" ng-show="editMode" ng-model="cts.selectedcontact.location.street"><br/>
角度代码:
$scope.toggle_save = function(contacts,data){
$scope.selectedcontact = {};
$http.put('http://localhost:3000/contacts/' + contacts.id)
.then(function(response){
console.log(response)
$scope.cts.selectedcontact = data;
})
}