我想在回调函数之后运行代码;但是,由于回调函数是回调函数,所以回调函数中的runFirst()函数运行在runSecond()函数之后。有什么简单的方法来补救这个问题吗?
$http.get($requestURL).success(function(response){
argument = runFirst();
});
});
runSecond(argument);发布于 2015-11-17 03:55:03
用承诺链。
$http.get( 'your url' ).then(
function( response ) {
return runFirst();
}
).then(
function( argument ) {
runSecond( argument );
}
);发布于 2015-11-17 03:34:52
你可以用承诺。
$http.get($requestURL).then(function(response){
argument = runFirst().then(runSecond());
});
});您只需确保runFirst()也返回一个承诺。
博士:$q文档
https://stackoverflow.com/questions/33748376
复制相似问题