-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merged feature/swal-component into master
- Loading branch information
Showing
4 changed files
with
99 additions
and
5 deletions.
There are no files selected for viewing
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
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 |
---|---|---|
@@ -1,11 +1,13 @@ | ||
import { NgModule } from '@angular/core'; | ||
import { SwalComponent } from './src/swal.component'; | ||
import { SwalDirective } from './src/swal.directive'; | ||
|
||
export * from './src/swal.component'; | ||
export * from './src/swal.directive'; | ||
|
||
@NgModule({ | ||
declarations: [SwalDirective], | ||
exports: [SwalDirective] | ||
declarations: [SwalComponent, SwalDirective], | ||
exports: [SwalComponent, SwalDirective] | ||
}) | ||
export class SweetAlert2Module { | ||
} |
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,35 @@ | ||
import { Component, EventEmitter, Input, Output } from '@angular/core'; | ||
import swal, { SweetAlertOptions, SweetAlertType } from 'sweetalert2'; | ||
|
||
@Component({ | ||
selector: 'swal', | ||
template: '' | ||
}) | ||
export class SwalComponent { | ||
@Input() public type: SweetAlertType; | ||
@Input() public title: string; | ||
@Input() public text: string; | ||
@Input() public html: string; | ||
@Input() public options: SweetAlertOptions; | ||
|
||
@Output() public confirm: EventEmitter<any> = new EventEmitter(); | ||
@Output() public cancel: EventEmitter<any> = new EventEmitter(); | ||
|
||
public show(): Promise<any> { | ||
const options = Object.assign({ | ||
type: this.type, | ||
title: this.title, | ||
text: this.text, | ||
html: this.html, | ||
}, this.options); | ||
|
||
const promise = swal(options); | ||
|
||
promise.then( | ||
(success) => this.confirm.emit(success), | ||
(dismiss) => this.cancel.emit(dismiss) | ||
); | ||
|
||
return promise; | ||
} | ||
} |
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