Skip to content

Instantly share code, notes, and snippets.

@gocs
Created February 8, 2023 13:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gocs/3c11a4f632ff5ce4827ae4f2d3286057 to your computer and use it in GitHub Desktop.
Save gocs/3c11a4f632ff5ce4827ae4f2d3286057 to your computer and use it in GitHub Desktop.
ng-sweetalert2 as simple as alert

simple SwalPortalDirective

The following example demonstrates a simple Swal with a button. In this example, you could provide more HTML within your HTML component rather than binding the HTML to an [html]. You would still need to import the SwalPortalTargets in your component.

import { SwalPortalTargets } from '@sweetalert2/ngx-sweetalert2';
export class MyComponent {
  public constructor(public readonly swal_targets: SwalPortalTargets) { }
  submit() { console.log("submit is clicked") }
}

Here, the container with swalPortal directive's value is the target's content:

<button [swal]="swal_portal" (confirm)="submit()">
  Swal button
</button>

<swal #swal_portal title="Swal Title" icon="warning">
  <ng-container *swalPortal="swal_targets.content">
    Please press <b>OK</b>?
  </ng-container>
</swal>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment