This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Injectable } from '@angular/core'; | |
@Injectable({ | |
providedIn: 'root' | |
}) | |
export class ExampleService { | |
constructor() { } | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@NgModule({ | |
providers: [ExampleService] | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Component({ | |
selector: 'app-example-page', | |
templateUrl: './app-example-page.component.html', | |
styleUrls: ['./app-example-page.component.css'], | |
providers: [ ExampleService ] | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let tstObj = { | |
value: 45, | |
getValue: function () { | |
return this.value; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
setTimeout(function () { | |
setTimeout(function () { | |
setTimeout(function () { | |
console.log("h"); | |
}, 1000); | |
}, 1000); | |
}, 1000); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
myPromise().then(data => { | |
console.log(data); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
myPromist().then(data => { | |
return myNewPromise(); | |
}). then(data => { | |
handleMyNewPromise(); | |
}).catch(error => { | |
handleAllErrors(); | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
myPromist().then(data => { | |
return myNewPromise(); | |
}). then(data => { | |
handleMyNewPromise(); | |
}).catch(error => { | |
handleAllErrors(); | |
}).finally(() => { | |
// clean approch | |
hideSpinner(); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let myPromise = new Promise((resolve) => { | |
// this is executer function | |
// need to have a parameter for the resolve function | |
setTimeout(() => { | |
// any value return by resolve function will receive as | |
// from then function | |
resolve("resolved"); | |
}, 1500); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const myPromise1 = new Promise(); | |
const myPromise2 = new Promise(); | |
Promise.all([myPromise1, myPromise2]). | |
then(([result1,result2])=> { | |
}); |