Last active
August 31, 2018 11:19
-
-
Save israeljrs/e1e45304d24885cc2d6412e681c18ac7 to your computer and use it in GitHub Desktop.
app.compoent para o artigo 11 do medium.
This file contains hidden or 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 { Component } from '@angular/core'; | |
import swal from 'sweetalert2'; | |
@Component({ | |
selector: 'app-root', | |
templateUrl: './app.component.html', | |
styleUrls: ['./app.component.scss'] | |
}) | |
export class AppComponent { | |
title = 'sample-delay'; | |
// cria uma função async | |
async btnOnClick() { | |
// loga no console o que vai acontecer. | |
console.log('Por favor aguarde 3s.'); | |
// Chama a função delay asyncronamente. | |
await this.delay(2000); | |
// Chama o sweetalert2 após o delay. | |
swal('Information', 'Mensagem com delay de 2000ms', 'success'); | |
} | |
// nossa função delay com suporte a promisse. | |
private delay(ms: number): Promise<boolean> { | |
return new Promise(resolve => { | |
setTimeout(() => { | |
resolve(true); | |
}, ms); | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment