search

Home  >  Q&A  >  body text

javascript - How to assign values ​​to variables using the data returned by angular http

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

过去多啦不再A梦过去多啦不再A梦2769 days ago722

reply all(3)I'll reply

  • PHP中文网

    PHP中文网2017-05-24 11:35:22

    Place the request in mainCtrl.

    reply
    0
  • 淡淡烟草味

    淡淡烟草味2017-05-24 11:35:22

    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

    reply
    0
  • 滿天的星座

    滿天的星座2017-05-24 11:35:22

    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.

    reply
    0
  • Cancelreply