Skip to content

Instantly share code, notes, and snippets.

@israeljrs
Last active August 31, 2018 11:19
Show Gist options
  • Save israeljrs/e1e45304d24885cc2d6412e681c18ac7 to your computer and use it in GitHub Desktop.
Save israeljrs/e1e45304d24885cc2d6412e681c18ac7 to your computer and use it in GitHub Desktop.
app.compoent para o artigo 11 do medium.
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