asynchronous - TypeScript/Angular 2 - call a function after another completes -
i have 2 functions call, want call second 1 after first 1 completes. how go doing that?
first function:
getdirectorysubfolders(node: any) { console.log('home:getdirectorysubfolders() entered...'); this._sdiservice.getdirectoriesatpath("desktop") .subscribe(res => { this.nodechildren = res; }); }
second function:
getchildren(node: any) { console.log('home:getchildren entered..'); return new promise((resolve, reject) => { settimeout(() => resolve(this.nodechildren.map((c) => { return object.assign({}, c, {}); })), 1000); }); }
there 2 simple ways call second function after first 1 finished - can under this.nodechildren = res;
or use finish parameter ()
:
getdirectorysubfolders(node: any) { console.log('home:getdirectorysubfolders() entered...'); this._sdiservice.getdirectoriesatpath("desktop") .subscribe(res => { this.nodechildren = res; this.getchildren(); <-- here }, () => { this.getchildren(); <-- or here }); }
when call getdirectorysubfolders()
function, getchildren()
called after completion of getdirectorysubfolders()
.
Comments
Post a Comment