Last active
May 1, 2019 10:54
-
-
Save Dssdiego/f4cf5a357563c2f1fd944f4d36f54afc to your computer and use it in GitHub Desktop.
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 { Injectable } from '@angular/core'; | |
import { MatDialog,MatSnackBar } from '@angular/material'; | |
@Injectable() | |
export class AlertService { | |
constructor( | |
private snackBar: MatSnackBar | |
) { } | |
showSnackBar(message: string) { | |
this.snackBar.open(message, null, { | |
duration: 2000, | |
}); | |
} | |
} |
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
constructor( | |
private confirmService: AppConfirmService // Serviço Nativo do Angular, não precisa ser criado no sistema | |
) { } | |
deleteItem(client) { | |
this.confirmService.confirm({ message: `Excluir o cliente "${client.name}"?` }) | |
.subscribe(res => { // Subscribe é uma função de observables, significa que está verificando se há resultado de retorno da função | |
if (res) { // Se houver resultado continua | |
this.clientsService.deleteClient(client) // Chama no serviço a função de excluir (no nosso caso aqui, vai existir um serviço de tasks) | |
.then(() => this.alertService.showSnackBar("Cliente Excluído com Sucesso"), // Após exclusão, chama a função de mostrar um snackbar no serviço (este serviço precisa ser criado no sistema, código dele acima) | |
err => { | |
this.alertService.showSnackBar("Ocorreu um Erro") // Se tiver tido um erro, mostra um snackbar com erro | |
console.error(err); | |
}); | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment