notiflix / Notiflix

Notiflix is a pure JavaScript library for client-side non-blocking notifications, popup boxes, loading indicators, and more that makes your web projects much better.

Home Page:https://notiflix.github.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Callbacks fail when calling typescript functions

DDriggs00 opened this issue · comments

Describe the bug
When adding a typescript variable to a callback function, the button which calls the does nothing when clicked.

To Reproduce
Steps to reproduce the behavior:

  1. Install in Angular via method 1 under installation (npm install, import)
  2. Import Notiflix import { Confirm } from 'notiflix';
  3. Create a Confirm as follows and call from a class function:
     Confirm.Show(
         'Notiflix Confirm',
         'Do you agree with me?', 
        'Yes',
         'No', 
        function(){
            // Yes button callback
            this.classvariable = true;
            alert('alert is a typescript function');
        },
        function(){
            // No button callback
            alert('alert is a non-typescript function'); 
        }
    ); 
  4. The "No" Button should work, and the "Yes" Button should not do anything

Expected behavior
The yes button sets this.classvariable to true then raises the alert.

Desktop

  • OS: Ubuntu 20.04
  • Browser: Firefox 81
  • Notiflix Version: 2.5.0 (latest)

Not tested on Mobile

Hi @DDriggs00

Firstly thanks for using Notiflix.

I did not get your expectation at all but maybe you can try the code below and feedback.

Thanks.

Furkan.

 // ....
 var aMysteriousThis = this;

 Confirm.Show(
     'Notiflix Confirm',
     'Do you agree with me?', 
    'Yes',
     'No', 
    function(){
        // Yes button callback
        aMysteriousThis.classvariable = true;
        alert('alert is a typescript function');
    },
    function(){
        // No button callback
        alert('alert is a non-typescript function'); 
    }
); 

Thank you, This is a good workaround.
I can confirm that it works with typescript 3.8/Angular 9

It would still be nice to not have to do a workaround like this, but I understand this is a pure JS library.