我正在使用 restangular,但我对“Put”方法有问题,它没有按预期工作
我的angularService代码
var userService = function (restangular) {
var resourceBase = restangular.all("account/");
restangular.addResponseInterceptor(function (data, operation, what, url, response, deferred) {
if (operation == "getList") {
return response.data;
}
return response;
});
this.getUserById = function (id) {
return resourceBase.get(id);
// return restangular.one("account", id).get();
};
this.updateUser = function(user) {
return user.Put();
};
}
我的 Controller 代码
var userEditController = function (scope, userService, feedBackFactory, $routeParams) {
scope.user = undefined;
scope.updateUser = function () {
userService.updateUser(scope.user).then(function (data) {
feedBackFactory.showFeedBack(data);
}, function (err) {
feedBackFactory.showFeedBack(err);
});
};
userService.getUserById($routeParams.id).then(function (data) {
scope.user = data.data; **// Please not here I am reading the object using service and this object is getting updated and pass again to the service for updating**
}, function (er) {
feedBackFactory.showFeedBack(er);
});
};
但我收到错误消息“Put”不是函数,我检查了用户对象,发现用户对象没有重新定义(没有找到任何其他方法)。我该如何解决
最佳答案
您只能“放置”数据对象。
customPUT([elem, path, params, headers])
是你想要的。像这样使用它:
Restangular.all('yourTargetInSetPath').customPUT({'something': 'hello'}).then(
function(data) { /** do something **/ },
function(error) { /** do some other thing **/ }
);
关于javascript - 如何在 restangular 中使用 PUT 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27587179/