question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Fire swal via template

See original GitHub issue

Hi all together,

I’d like to fire swal alerts via template without going the ViewChild-way.

Example: <swal *ngIf="(error$ | async) as error" [title]="error.title" [text]="error.text" icon="error"> </swal>

The really big advantage I see here is, that my redux store does all the work and I don’t need to do the show and hide logic.

I’d be really grateful if anybody knows a solution to this. Even a workaround (without ‘codebehind’) would be fine.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:11 (6 by maintainers)

github_iconTop GitHub Comments

3reactions
toveruxcommented, Nov 29, 2019

This option will also be available in forRoot(). And to set native SweetAlert options, you can actually already do that in forRoot() too, by providing a SweetAlert mixin, it’s just a bit verbose 😃 (*)

import { SweetAlert2Module } from '@sweetalert2/ngx-sweetalert2';

// using a separate function for AoT, that doesn't likes arrow syntax expressions in @NgModule
export function provideSwal() {
    return import('sweetalert2').then(({ default: Swal }) => Swal.mixin({
        heightAuto: false
    }))
} 

@NgModule({
    imports: [
        SweetAlert2Module.forRoot({ provideSwal }) // also possible in forChild, btw
    ]
})
export class AppModule {
}

(*) previous version allowed to pass options direclty, but that became redundant with mixins. And I’ve been able to simplify the integration code in a very generic way with provideSwal. So this became the way to specify global options too.

2reactions
ChristofFritzcommented, Dec 5, 2019

No problem at all! After all, it’s “just” open source and you are doing it in your free time (i guess?).

Read more comments on GitHub >

github_iconTop Results From Across the Web

SweetAlert2 - a beautiful, responsive, customizable and ...
A beautiful, responsive, customizable and accessible (WAI-ARIA) replacement for JavaScript's popup boxes.
Read more >
how to have 2 swal templates open - Stack Overflow
is it possible to have two swal templates from sweeter alerts open at the same time? picture this: I am developing a blog...
Read more >
Guides - SweetAlert
The only code that's specific to SweetAlert is the swal.setActionValue() and the swal() call at the end. The rest is just basic React...
Read more >
Creating Pretty Popup Messages Using SweetAlert2 - Code
There are two ways to create a sweet alert using the Swal.fire() ... If you interacted with the alert messages in the first...
Read more >
SweetAlert2 (Advance version of SweetAlert) - GeeksforGeeks
Example 1: In this example, we will simply display sweetAlert2. ... Swal.fire( 'Nice to meet you' , '' , 'success' );.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found