Hey there! I've been experimenting with the promise technique to wait for calls inside a for loop, but I'm having trouble making it work.
When I try "return mainArr," it returns undefined.
//export CSV
Looping Through Data
//Assumes that data is a list of JSON objects
function getCustomData(data){
var mainArr=[];
for (var i = 0; i < data.length; i++) {
var obj={};
obj.word = $('#type-ahead-input').val();
obj.synonym = data[i].word;
obj.similarityCount = (data[i].similarityCount).toFixed(2);
obj.emailCount = data[i].occuranceCount;
obj.synonymlist = getSynonymList(data[i].word);
mainArr.push(obj);
}
return mainArr;
}
function getSynonymList(inputWord){
return WordService.getSynonymList({
ids : inputWord
}).$promise
.then(function($response) {
var output = $response;
var wordList =[];
for (var i = 0; i < output.length; i++) {
wordList.push(output[i].word);
}
return wordList;
});
}
Factory Resource Call Signature
getSynonymList : {
method : 'GET',
isArray: true,
async : false,
url : appRoot + '/synonym',
params : {
word : '@word'
}
},