This could have something to do with #335, I don't know.
I'm trying to use sweetalert2 on my angular2 project. What I want to do is create an AlertService and use it to create the alerts. Here's what I'm doing:
import { Injectable } from '@angular/core';
import * as swal from 'sweetalert2';
// declare var swal:any;
export interface IAlertService {
alert(message: string): void;
info(message: string): void;
error(message: string): void;
success(message: string): void;
}
@Injectable()
export class AlertService implements IAlertService {
alert(message: string): void {
debugger;
}
info(message: string): void {
}
error(message: string): void {
}
success(message: string): void {
}
}
But I cannot get swal to work. It is always a null reference. I tried the way it's written on the home page: import { default as swal } from 'sweetalert2' but it's not working as well. I've installed the typings but it's not working as well. Any ideas on how to make it work?
Thanks
Hi.
dist/sweetaler2.js In the file does not export.
Code form file:
if (window.Sweetalert2) window.sweetAlert = window.swal = window.Sweetalert2;
This module use in global scope.
Maybe better to do the export?
module.export = Sweetalert2;
@eestein if you happen to use angular-cli for your project you can take a look at this implementation: https://github.com/joshterrill/ng2-cli-sweetalert2
I'm using it this way (referencing dist/sweetalert2.js from angular-cli.json) and that works, thought I'd rather not add files to angular-cli.json but just do an import 'sweetalert2' where I need it.
@beeman that's cool, thanks :)
Done in v6.2.5 via #381.
Most helpful comment
@eestein if you happen to use
angular-clifor your project you can take a look at this implementation: https://github.com/joshterrill/ng2-cli-sweetalert2I'm using it this way (referencing
dist/sweetalert2.jsfromangular-cli.json) and that works, thought I'd rather not add files toangular-cli.jsonbut just do animport 'sweetalert2'where I need it.