Skip to content

Commit

Permalink
created service for common sweetalert custom method
Browse files Browse the repository at this point in the history
  • Loading branch information
pragati-atharva committed Sep 22, 2022
1 parent 698907d commit df6c784
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { TestBed } from '@angular/core/testing';

import { CustomSweetalertService } from './custom-sweetalert.service';

describe('CustomSweetalertService', () => {
let service: CustomSweetalertService;

beforeEach(() => {
TestBed.configureTestingModule({});
service = TestBed.inject(CustomSweetalertService);
});

it('should be created', () => {
expect(service).toBeTruthy();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { Injectable } from '@angular/core';
import Swal from 'sweetalert2';

@Injectable({
providedIn: 'root',
})
export class CustomSweetalertService {
constructor() {}

sweetAlertMethod(
title: string,
onConfirm: () => void,
onDeny?: () => void,
showDenyButton?: boolean,
denyButtonText?: string,
confirmButtonText?: string,
confirmButtonColor?: string,
reverseButtons?: boolean,
focusDeny?: boolean
) {
Swal.fire({
title: title,
showDenyButton: showDenyButton || true,
denyButtonText: denyButtonText || 'NO',
confirmButtonText: confirmButtonText || 'YES',
confirmButtonColor: confirmButtonColor || 'white',
reverseButtons: reverseButtons || true,
focusDeny: focusDeny || true,
}).then((result) => {
if (result.isConfirmed) {
onConfirm();
} else {
if (onDeny) onDeny();
}
});
}
}

0 comments on commit df6c784

Please sign in to comment.