我想在另一個地方調用urls,但不是所有的都在同一時間,但無論我怎麼嘗試,他們似乎都發生在同一時間。這是我現在所擁有的...陸續訪問網址
$http.get('/some/url/foo1')
.then($http.get('/some/url/foo2'))
.then($http.get('/some/url/foo3'))
.then($http.get('/some/url/foo4'))
.then($http.get('/some/url/foo5'))
.then($http.get('/some/url/foo6'))
.then($http.get('/some/url/foo7'))
.then($http.get('/some/url/foo8'))
.then($http.get('/some/url/foo9'))
.then($http.get('/some/url/foo10'))
.then($http.get('/some/url/foo11'))
.then($http.get('/some/url/foo12'))
.then($http.get('/some/url/foo13'))
.then($http.get('/some/url/foo14'));
這些不能同時發生,當一個完成時,我希望下一個啓動。
編輯:我也試圖把get
在這樣的功能,但他們仍然都被調用,同時
$http.get('/some/url/foo1')
.then(rebuildModel('foo2'))
.then(rebuildModel('foo3'))
.then(rebuildModel('foo4'))
.then(rebuildModel('foo5'))
.then(rebuildModel('foo6'))
.then(rebuildModel('foo7'))
.then(rebuildModel('foo8'))
.then(rebuildModel('foo9'))
.then(rebuildModel('foo10'))
.then(rebuildModel('foo11'))
.then(rebuildModel('foo12'))
.then(rebuildModel('foo13'))
.then(rebuildModel('foo14'));
function rebuildModel(modelName) {
return $http.get('/some/url/' + modelName);
}
EDIT2:這個工作...我看到我做錯了什麼
function rebuildModel(modelName) {
return function() {
return $http.get('/some/url/' + modelName);
}
}
,你還在「通話中」的功能,而不是提供了一個函數的定義。修復你的例子try:function rebuildModel(modelName){return function(){return $ http.get('url'+ modelName); }}; – pixelbits 2015-04-03 02:47:36