Can not implement SweetAlert in ionic 2


#1

Dear All,

for my ionic 2 app, i am using alert which is working,

let alert = this.alertCtrl.create({
      title: 'Create New SHop',
      subTitle: 'Create New Shop Successfully',
      buttons: ['Ok']
    });

alert.present();

Now i am try to use sweetAlert, which is not woking, please help me to make it workable.

import { default as swal } from ‘sweetalert2’;

constructor( public navCtrl: NavController, public geolocation: Geolocation, public addshopservice: Addshopservice, public alertCtrl: AlertController) {
}

let alertsweet=swal(
‘Good job!’,
‘You clicked the button!’,
‘success’
);

what shoule be need use instead of “alert.present()”.

Thanks in advance.


#2

What is this sweetAlert you are talking about? Are you expecting us to google ourselves?


#3

I would really think hard about whether you absolutely can’t live with Ionic’s alert.

If you are still convinced that you can’t, look for an angular 2 service that wraps sweetalert. There seem to be a few. I haven’t used any of them, because I’m perfectly happy with Ionic’s alert.


#4

use this it works in ionic

show(){
let sweetAlrt = swal({
title: ‘Are you sure?’,
text: ‘You will not be able to recover this imaginary file!’,
type: ‘warning’,
showCancelButton: true,
confirmButtonText: ‘Yes, delete it!’,
cancelButtonText: ‘No, keep it’
}).then((result) => {
if (result.value) {
swal(
‘Deleted!’,
‘Your imaginary file has been deleted.’,
‘success’
)
// result.dismiss can be ‘overlay’, ‘cancel’, ‘close’, ‘esc’, ‘timer’
} else if (result.dismiss === ‘cancel’) {
swal(
‘Cancelled’,
‘Your imaginary file is safe :)’,
‘error’
)
}
})
return sweetAlrt
}