当存在某个值时,我需要调用服务函数。我调用一个服务,获取数据然后我需要调用另一个服务来对第一个服务调用的结果进行一些字符串操作。
实际上我会模拟检查第一次服务的调用何时完成,但似乎不是一个很好的方法。
$scope.result = function(){
Report.startQueue(url, function(response, reports){
$scope.progress = response;
$scope.report = reports;
if(response === "last"){
$scope.string= keyService.stringOperations($scope.report.MyString);
}
});
}
如果我直接打电话
$scope.string= function(item) {
return keyService.stringOperations(item);
}
我收到错误,因为此刻字符串尚未就绪。在keyService中我使用字符串替换方法,如果字符串为空则抛出错误
[PLUNKR] http://plnkr.co/edit/gcvOZL