I am facing an issue while updating the guitar object in my AngularJS application. The operation is performed using the updateGuitar controller with ngMock backend.
After updating the guitar object, the put request is processed by the carService. However, I encounter a problem in accessing the updated object in my carView controller. So, when I navigate to location.path(/car/view/id
, I cannot retrieve the updated object.
Below is the code for my guitarView controller:
window.app.controller('guitarViewCtrl', ['$scope', '$routeParams', '$location',
'GuitarService', function ($scope, $routeParams, $location, GuitarService) {
'use strict';
$scope.guitarId = $routeParams.guitarId;
initGuitar($scope.guitarId);
function initGuitar(guitarId) {
GuitarService.showDetails(guitarId).then(function success(guitar) {
$scope.guitar = guitar;
}, function error(response) {
});
}
}]);
Regarding My GuitarService: I have been advised to populate the Guitars within this service (currently done in mock.js), but I am unsure of how to go about it.
window.app.service('GuitarService', ['HTTPService', '$http', function (HTTPService, $q, $http) {
'use strict';
this.showDetails = function (opleidingsprofielId){
// HTTP service returns correct urls
return HTTPService.get('/opleidingsprofiel/view/' + opleidingsprofielId);
this.put = function (opformUpdate, opleidingsprofielId) {
var deferred = $q.defer();
$http.put('/#/opleidingsprofiel/:opleidingsprofielId/update', opformUpdate)
.then(function resolve(response){
deferred.resolve(response.data);
}, function reject(response){
deferred.reject(response);
});
return deferred.promise;
};
}]);