我有两个有关AngularJS承诺的问题:如何创建我自己的承诺?
- 我该如何创建自己的承诺?
请参见下面的代码:
function controller($http) {
var dataCache;
function getData(){
if(dataCache != null){
// should return my own promise here
// to pass the value of 'dataCache' to 'then' immediately
} else {
return $http.get('...some url ...');
}
}
}
- 如何返回最后一个承诺?
代码:
function controller($http) {
var urlArr = ['url1', 'url2', 'url3'];
function getDataOneByOne() {
// should call $http.get() for the url in the 'urlArr' one after another in a chain
// and return the last promise
}
}
https://docs.angularjs.org/api/ng/service/$q – Ian 2014-09-06 01:37:16
请在将来写每个帖子一个问题。尝试以对社区最有帮助的方式撰写你的帖子(未来的观众)。 – m59 2014-09-06 01:56:13