Created
April 24, 2019 14:05
-
-
Save Dssdiego/99eb26099ef442e49226a73e54f4f0e9 to your computer and use it in GitHub Desktop.
Alert Service
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
<div class="text-center"> | |
<img class="mb-05" src="{{ image }}" alt=""/> | |
<h6 class="m-0 pb-1">{{ title }}</h6> | |
</div> |
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
.mat-dialog-content { | |
min-height: 122px; | |
} |
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, OnInit } from '@angular/core'; | |
import { MatDialogRef } from '@angular/material'; | |
@Component({ | |
selector: 'app-alert-service', | |
templateUrl: './alert.component.html', | |
styleUrls: ['./alert.component.scss'] | |
}) | |
export class AlertComponent implements OnInit { | |
title; | |
message; | |
image; | |
constructor(public dialogRef: MatDialogRef<AlertComponent>) {} | |
ngOnInit() { | |
// console.log(this.image); | |
} | |
} |
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, MatDialogRef } from '@angular/material'; | |
import { Observable } from 'rxjs'; | |
import { AlertComponent } from './alert.component'; | |
@Injectable() | |
export class AlertService { | |
dialogRef: MatDialogRef<AlertComponent>; | |
constructor(private dialog: MatDialog) { } | |
public open(title: string = 'title', image: string = 'ic_check'): Observable<boolean> { | |
this.dialogRef = this.dialog.open(AlertComponent, { disableClose: true, backdropClass: 'light-backdrop'}); | |
this.dialogRef.updateSize('200px'); | |
this.dialogRef.componentInstance.title = title; | |
this.dialogRef.componentInstance.image = image; | |
this.dialogRef.afterClosed(); | |
return this.dialogRef.afterClosed(); | |
} | |
public close() { | |
if(this.dialogRef) | |
this.dialogRef.close(); | |
} | |
} |
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
showSuccessMessage(msg) { | |
setTimeout(() => { | |
this.alertService.close(); | |
this.loader.close(); | |
this.getData(); | |
}, 2000); | |
this.alertService.open(msg, this.assetService.getCheckIcon()); | |
} | |
showErrorMessage(err) { | |
setTimeout(() => { | |
this.alertService.close(); | |
}, 3000); | |
this.alertService.open("Ocorreu um Erro", this.assetService.getCancelIcon()); | |
console.error(err); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment