简体   繁体   English

angular-fullstack PUT将不会在后端更新

[英]angular-fullstack PUT will not update in backend

I am trying to run a PUT updating the status of an issue from "unresolved" to "resolved". 我正在尝试运行PUT,将问题的状态从“未解决”更新为“已解决”。 However, I keep getting TypeError: $scope.details.$update(); 但是,我不断收到TypeError: $scope.details.$update(); is not a function. 不是功能。

I am using the angular-fullstack yeoman generator. 我正在使用角度全栈yeoman生成器。

I have tried following different guides here and here . 我曾尝试在这里这里遵循不同的指南。

here is my code: 这是我的代码:

update function in the API API中的更新功能

 export function update(req, res) {
   if (req.body._id) {
     delete req.body._id;
   }
   WCS.findByIdAsync(req.params.id)
     .then(handleEntityNotFound(res))
     .then(saveUpdates(req.body))
     .then(respondWithResult(res))
     .catch(handleError(res));
 }

functions in my controller to retrieve and manipulate the data. 控制器中的函数来检索和处理数据。

// Search
  $scope.theId = '';

  $scope.details = {};

// Pull function
  $scope.getVOC = function () {
    if ($scope.theId.length === 24) {
      $http.get('http://localhost:9000/api/WCS/' + $scope.theId)
        .success(function(data) {
          $scope.details = data;
        });
    } else {
      alert('Please use an existing ID.');
    }
  };

  // Put function
  $scope.updateVOC = function () {
      $scope.details.$update();
  };

And my html: 和我的HTML:

  <form >
    <input ng-model='theId' type='text'>
    <button type="submit" class="btn btn" ng-click="getVOC()">Search</button>
    <button type="submit" class='btn' ng-click='updateVOC()' name="button">Update</button>
  </form>

<div>
<table class="table table-hover table-bordered">
<h4>Customer Information</h4>
<tr>
  <td class="col-sm-2">Name:</td>
  <td>{{details.name}}</td>
</tr>
<tr>
  <td>Email:</td>
  <td>{{details.email}}</td>
</tr>
<tr>
  <td>Phone:</td>
  <td>{{details.phone}}</td>
</tr>
<tr>
  <td>Company:</td>
  <td>{{details.company}}</td>
</tr>
<tr>
 <td>Status:</td>
 <td>
   <select class='form-control col-sm-2' ng-model="details.resolutionStatus">
     <option>resolved</option>
     <option>unresolved</option>
   </select>
     </td>
</tr>

When I select the resolved option and click on the updateVOC function it shows on the scope that the resolution status is now 'resolved', but that change does not update the database. 当我选择解决的选项并单击updateVOC函数时,它在作用域上显示分辨率状态现在为“已解决”,但是该更改不会更新数据库。 I need it to save in the database. 我需要将其保存在数据库中。

ng-resource没有$ update,但是您可以自己进行自定义PUT请求

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM