I've read a few questions with this same issue but none work for my personal case. I'm trying to delete an entry off a ng-repeat list.
This is my view (the ng-shows are for editing purposes):
<tr ng-repeat="entry in entries" ng-cloak>
<th>{{ $index + 1 }}</th>
<td>
<span ng-show="!editMode[$index]">{{ entry.username }}</span>
<input ng-show="editMode[$index]" type="text" ng-model="entry.username"/>
</td>
<td>
<span ng-show="!editMode[$index]">{{ entry.date }}</span>
<input ng-show="editMode[$index]" value="{{entry.date}}"/>
</td>
<td>
<span ng-show="!editMode[$index]">{{ entry.hours }}</span>
<input ng-show="editMode[$index]" type="text" ng-model="entry.hours"/>
</td>
<td>
<span ng-show="!editMode[$index]">{{ entry.payout }}</span>
<input ng-show="editMode[$index]" type="text" ng-model="entry.payout"/>
</td>
<td>
<button ng-show="!editMode[$index]" type="submit" class="btn btn-primary" ng-click="deleteEntry($index)">Delete</button>
<button ng-show="!editMode[$index]" type="submit" class="btn btn-primary" ng-click="editEntry($index)">Edit</button>
<button ng-show="editMode[$index]" type="submit" class="btn btn-primary" ng-click="saveUpdate($index)">Update</button>
<button ng-show="editMode[$index]" type="submit" class="btn btn-primary" ng-click="cancelUpdate($index)">Cancel</button>
</td>
</tr>
My angular controller:
// DELETE
$scope.deleteEntry = function(id) {
// delete entry from DB using clicked listing's id
$http.delete('/api/entry/' + id)
.success(function(data) {
$scope.entry = data;
})
.error(function(data) {
console.log('Error: ' + data);
});
// then update page with remaining entries
$http.get('/api/entries').then(function(response){
$scope.entries = response.data;
});
};
In my apiController.js
app.delete('/api/entry/:entry_id', function(req, res){
Entries.remove({
_id : req.params.entry_id
}, function(err, entry)
if (err)
res.send(err);
// get and return remaining entries
Entries.find(function(err, entries) {
if (err)
res.send(err)
res.json(entries);
});
});
});
When I remove the Entries.find function the error goes away but the delete call no longer works.
I'm using mongoose to connect to my DB.
What am I missing here?