javascript - How to assign values to variables using the data returned by angular http
过去多啦不再A梦2017-05-24 11:33:22
0
3
680
How to get rid of the asynchronous problem. The http request will return the data number, and then use this number globally. However, due to asynchronous reasons, the assignment variable of this number is always undefined. How to deal with this
I have encountered this before, but we are using an http service written by ourselves, which returns a promise object, so we have to use then to obtain the data inside. I looked at this method written by a colleague, and it seems that it returns the response.data of http in Angular. I don’t know if this will help you
Put the logic code that will use the data into the callback function of the asynchronous request success to ensure that the data has been obtained when the code that needs to use the data is executed.
Place the request in mainCtrl.
I have encountered this before, but we are using an http service written by ourselves, which returns a promise object, so we have to use then to obtain the data inside. I looked at this method written by a colleague, and it seems that it returns the response.data of http in Angular. I don’t know if this will help you
Put the logic code that will use the data into the callback function of the asynchronous request success to ensure that the data has been obtained when the code that needs to use the data is executed.