I need two independend arrays to work with them inside function. So I returning promises. But when it's getting to arrayOne.length it's not waiting untill promises resolve. How to make it work then?
this.workWithArrays = function () {
var arrayOne = this.getArrayOne();
var arrayTwo = this.getArrayTwo();
for (var i = 0; i < arrayOne.length; i++) {
.....
}
getArrayOne and getArrayTwo are mostly identical:
this.getArrayOne = function() {
return $http.get('/1').then(
function success(response) {
return response.data;
},
function error(data) {
console.log(data);
}
);
}