2016-02-15 30 views
0

我試圖運行一個PUT,將問題的狀態從「未解決」更新爲「已解決」。但是,我不斷收到TypeError:$scope.details.$update();不是一個函數。angular-fullstack PUT不會在後端更新

我正在使用angular-fullstack yeoman generator。

我試過以下不同指南herehere

這裏是我的代碼: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)); 
} 

功能,檢索和處理數據。

// 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(); 
    }; 

而且我的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> 

當我選擇瞭解決選項,並單擊updateVOC功能它顯示的範圍,該決議狀態現在「解決」,但該更改不會更新數據庫。我需要它來保存在數據庫中。

+0

我看不出'$ scope.details。$更新()'在你已經源定義提供。我只是看到你在呼喚它。你確定它的定義嗎? – peteb

+0

@peteb,我將如何去定義它? – Rarepuppers

回答

0

ng-resource沒有一個$更新,但是你可以做一個自定義的PUT請求自己