Skip to content

Instantly share code, notes, and snippets.

View rasikag's full-sized avatar
🎯
Focusing

Rasika Gayan Gunarathna rasikag

🎯
Focusing
View GitHub Profile
import { Injectable } from '@angular/core';
@Injectable({
providedIn: 'root'
})
export class ExampleService {
constructor() { }
}
@NgModule({
providers: [ExampleService]
})
@rasikag
rasikag / examplecomponent.ts
Last active March 5, 2019 13:14
examplecomponent.ts
@Component({
selector: 'app-example-page',
templateUrl: './app-example-page.component.html',
styleUrls: ['./app-example-page.component.css'],
providers: [ ExampleService ]
})
let tstObj = {
value: 45,
getValue: function () {
return this.value;
}
}
setTimeout(function () {
setTimeout(function () {
setTimeout(function () {
console.log("h");
}, 1000);
}, 1000);
}, 1000);
myPromise().then(data => {
console.log(data);
});
myPromist().then(data => {
return myNewPromise();
}). then(data => {
handleMyNewPromise();
}).catch(error => {
handleAllErrors();
})
myPromist().then(data => {
return myNewPromise();
}). then(data => {
handleMyNewPromise();
}).catch(error => {
handleAllErrors();
}).finally(() => {
// clean approch
hideSpinner();
});
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);
});
const myPromise1 = new Promise();
const myPromise2 = new Promise();
Promise.all([myPromise1, myPromise2]).
then(([result1,result2])=> {
});