juan-manuel-alberro / angular-sweetalert-service

Angular (not AngularJS) wrapper for SweetAlert 2
MIT License
13 stars 3 forks source link

Error #2

Open b-mi opened 6 years ago

b-mi commented 6 years ago

Installed angular wrapper, I use angular 4, and got this error:

ERROR TypeError: myWindow.Sweetalert2 is not a function at SweetAlertService.webpackJsonp.../../../../angular-sweetalert-service/js/service/sweetalert2.service.js.SweetAlertService.confirm (sweetalert2.service.js:25)

In component code I used

import { SweetAlertService } from 'angular-sweetalert-service';
not
import { SweetAlertService } from 'angular-sweetalert'; // this not work

Then, command from your page end with error:

        this.alertService.confirm({
            title: 'Delete account?'
          })
          .then(() => {
            this.alertService.success({
              title: 'Account deleted'
            });
          })
          .catch(() => console.log('canceled'));
juan-manuel-alberro commented 6 years ago

Hello @b-mi I'll take a look, maybe a new version was released and is not backward compatible.

tunathoni commented 6 years ago

Hello @juan-manuel-alberro i also get an error like this, is it was resolved ? or still not yet ?

sangwin commented 6 years ago

+1. Not working at all

jeffreypolk commented 6 years ago

You need to manually include sweetalert2 for this to work.

b-mi commented 6 years ago

@jeffreypolk - how exactly include sweetalert2 'manually '? I use instructions for install from author - but it not work. Did you try your solution on angular 4?

jeffreypolk commented 6 years ago

Yes using Angular4. Not sure if it's the "right" way, but I just included sweetalert2 CDN js and css references in my index.html

sokphea-chea commented 6 years ago

I have the same problem like b-mi, and I think the problem come from webpack compile.

PixeliGer commented 6 years ago

@b-mi I found that 'manual installation' means installing and adding SweetAlert2 in angular.cli.json

First Install SweetAlert2 vía npm npm install --save sweetalert2

In your angular.cli.json include the css and js files

"styles": [
        ...
        "../node_modules/sweetalert2/dist/sweetalert2.min.css",
        ...
      ],
"scripts": [
          ...
          "../node_modules/sweetalert2/dist/sweetalert2.min.js",
          ...
      ],

Now runng-serve again, and angular-sweetalert-service will work without problems.

Note

Im still with the webpack warning about compatibility