【发布时间】:2016-06-16 18:18:40
【问题描述】:
在我的 AngularJS 应用程序中更新我的吉他对象时遇到问题。它在 ngMock 后端运行
吉他对象使用 updateGuitar 控制器进行更新。然后 carService 将处理 put 请求。
问题在于在我的 carView 控制器中获取更新的对象,所以当我执行 location.path(/car/view/id 或其他操作时,我会得到更新的对象。
这是我的 guitarView 控制器:
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) {
});
}
}]);
我的吉他服务: 有人说我需要在此服务中填充我的吉他(我现在在 mock.js 中执行此操作)但我不知道该怎么做。
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;
};
}]);
【问题讨论】:
-
对不起,我更新了我的代码,应该已经编辑了帖子本身。上次。
标签: javascript angularjs