我正在使用angularjs和Restangular。我想通过调用一些restangular服务为该对象赋值,之后更新的对象应该用于后期目的,如邮政编码。
代码块是:
$scope.myObject={};
Restangular.one("getProperties").get().then(function(properties){
$scope.myObject.properties=properties;
});
var postData = Restangular.all('AnotherPostService');
postData.post($scope.myObject).then(function (returnedObject) {
});
}, function (error) {
});
首先,我想调用getProprties rest服务,该服务应该将值分配给$scope.myObject.properties
对象,然后将更新$scope.myObject
传递给post方法AnotherPostService
以进行与数据库相关的更新任务。< / p>
我的问题是在为对象分配属性之前调用post方法,如何限制/分配调用rest服务的优先级,以便在初始化值时调用post方法?
答案 0 :(得分:0)
只需创建一个函数,并在第一次调用返回时调用它,如下所示:
$scope.myObject = {};
Restangular.one("getProperties").get().then(function(properties){
$scope.myObject.properties = properties;
doSecondOperation();
});
function doSecondOperation() {
var postData = Restangular.all('AnotherPostService');
postData.post($scope.myObject).then(
function (returnedObject) {
},
function (error) {
}
);
};
或者,如果您不需要任何其他内容来调用它,只需在设置doSecondOperation
后立即将$scope.myObject.properties
方法中的实际代码直接放在第一个操作的成功处理程序中。
你的牙套也有点乱了......我想我修好了......:)