Search code examples
javascriptasync-awaitweb-deployment

How to display loading dialog until data is fetched in javascript


I want to display a loading dialog or screen until my data is completely fetched but don't know how to do it I saw some examples about async/await and promises but from there I am not getting any idea.so, please help me if someone knows how to do it.


Solution

  • You can use a flag variable to decide to show the dialog or not.

    let flag = false # disable dialog in default
    
    # bind the update function to some element
    async update(){
      flag = true # enable dialog before api call
      const data = await fetchData() # fetch data
      flag = false # disable dialog after all data is fetched
    }