angular - How to call method i sweetalert 2 -


in angular 4 project using theme sweetalert 2, want call method when user click on confirm button, seems can't call method inside function

swal({   title: 'are sure?',   text: "you won't able revert this!",   type: 'warning',   showcancelbutton: true,   confirmbuttoncolor: '#3085d6',   cancelbuttoncolor: '#d33',   confirmbuttontext: 'yes, delete it!' }).then(function () {    // want call method here can't this.mymethod()  }) 

i know it's not angular sweetalert possible make work without change?

use arrow function notation () =>. when use function keyword, loose access this. change code below instead:

swal({   title: 'are sure?',   text: "you won't able revert this!",   type: 'warning',   showcancelbutton: true,   confirmbuttoncolor: '#3085d6',   cancelbuttoncolor: '#d33',   confirmbuttontext: 'yes, delete it!' }).then(()=> {    this.mymethod(); // should execute  }) 

Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -