angularjs - Looks like $http Service takes time to load the contents -


have written service fetch values promise , set values variables in service.

retrives promise , sets value variables in service

 getvaluefrompromise =function(){        mypromise.then(function(res){          myarray =res;          console.log("error");        }); }                            

this functionality has been coupled controller in such way returns array

this.getitems = function(){         getvaluefrompromise(); //line1        console.log(myarray); //line2        return myarray; //line3 }; 

my question revolves around getitemsmodule invoke getitempromise() set value variable myarray.

  • question 1: happens in console find myarray [] empty @ while loading ui. once refresh controller, values in myarray[]. suspect because in getitems() promise takes time in evaluating .get('url') , since operation done in asynchronous manner myarray values gets returned before promise evaluated.is suspected right?
  • question 2: if suspection in question1 right, how make line3 wait till line1 gets completed.also kindly enlighten me if anywhere wrong.


Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -