async lsEntered(){ if(this.service.wd == '') { await basic((this.service.wd)); } else { await basic(('/'+this.service.wd)); } this.files = await JSON.parse(localStorage.getItem('FILENAMES')); var filesList = document.getElementById(this.trackLine.toString()); var li; for (var i = 0; i < this.files.length; i++) { li = document.createElement('li'); li.appendChild(document.createTextNode(this.files[i].name)); filesList.appendChild(li); } localStorage.clear(); } I want to wait until basic is finished and JSON.parse finishes before displaying the values in the DOM. I'm getting the values of the previous call every time which is tell me the async is no working. To be fair I don't have tons of TS experience.
Edit: This is basic I was hoping not to have to deal with it as it's a javascript function and fragily integrated into this app.
var basic = function (path) { var ACCESS_TOKEN = ''; var dbx = new Dropbox({ accessToken: ACCESS_TOKEN }); dbx.filesListFolder({ path: path }) .then(function (response) { localStorage.setItem('FILENAMES',JSON.stringify(response.entries)); console.log(response); }) .catch(function (error) { console.error(error); }); return false; }
basic.basicJSON.parsedoes not return a promise, so you should omit theawaittherebasicmuch more flexible to use.