-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
created service for common sweetalert custom method
- Loading branch information
1 parent
698907d
commit df6c784
Showing
2 changed files
with
53 additions
and
0 deletions.
There are no files selected for viewing
16 changes: 16 additions & 0 deletions
16
src/app/core/shared/services/sweetalert/custom-sweetalert.service.spec.ts
This file contains 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
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(); | ||
}); | ||
}); |
37 changes: 37 additions & 0 deletions
37
src/app/core/shared/services/sweetalert/custom-sweetalert.service.ts
This file contains 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
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(); | ||
} | ||
}); | ||
} | ||
} |