Skip to content

Commit

Permalink
feat(SwalDirective): use new SweetAlert2 swal.argsToParams helper fun…
Browse files Browse the repository at this point in the history
…ction
  • Loading branch information
toverux committed Mar 7, 2018
1 parent 4ffc52d commit ae80949
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions src/swal.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@ import {
ComponentFactoryResolver, ComponentRef, Directive, EventEmitter, HostListener, Input, OnDestroy, OnInit, Output,
ViewContainerRef
} from '@angular/core';
import { SweetAlertOptions, SweetAlertType } from 'sweetalert2';
import swal, { SweetAlertOptions, SweetAlertArrayOptions } from 'sweetalert2';
import { SwalComponent } from './swal.component';

export type SimpleSweetAlertOptions = [string, string, SweetAlertType | null];

/**
* [swal] directive. It takes a value that defines the Sweet Alert and can be of three types:
*
Expand All @@ -31,14 +29,13 @@ export class SwalDirective implements OnInit, OnDestroy {
* SweetAlert2 options or a SwalComponent instance.
* See the class doc block for more informations.
*/
@Input() public set swal(swal: SwalComponent | SweetAlertOptions | SimpleSweetAlertOptions) {
if (swal instanceof SwalComponent) {
this.swalInstance = swal;
} else if (Array.isArray(swal)) {
this.swalOptions = {};
[this.swalOptions.title, this.swalOptions.text, this.swalOptions.type] = swal;
@Input() public set swal(options: SwalComponent | SweetAlertOptions | SweetAlertArrayOptions) {
if (options instanceof SwalComponent) {
this.swalInstance = options;
} else if (Array.isArray(options)) {
this.swalOptions = swal.argsToParams(options);
} else {
this.swalOptions = swal;
this.swalOptions = options;
}
}

Expand Down

0 comments on commit ae80949

Please sign in to comment.