I have a $resource which I use to handle entity's crud http requests. It's wrapped in my custom service which at the moment doesn't add any functionality, so never mind it - it's just old plain $resource:
app.factory('coursesService', ['$resource', coursesService]);
function coursesService($resource) {
return $resource('/api/courses/:id', {
id: '@id'
}, {
update: {
method: 'PUT'
}
});
}
So, I am trying to delete an instanse in my controller (which is stored in courseToDelete
property of the controller object):
this.courseToDelete.$remove()
I am mocking backend with $httpBackend service from ngMockE2E module:
$httpBackend.whenDELETE(/api\/courses\/(.+)/, undefined, undefined, ['id'])
.respond(function(method, url, data, headers, params) {
clientStorage.deleteCourse(params.id);
return [200, {}];
});
So when $resource sends DELETE http request I want to be able to delete it from my localstorage (because I don't have a backend, data stored in localstorage as serialized JSON string)
The Object that I'm trying to delete:
{
id: 1,
name: 'Course 1',
duration: 380,
description: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.' +
' Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.' +
' Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur' +
' sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.',
created: new Date(2011,10,30),
authors: [
'Пушкин', 'Лермонтов'
]
}
From the docs I expected that my params
parameter will have id
property on it but when the function executes params
is undefined, although all other params look fine. What am I doing wrong here?