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:
- Install in Angular via method 1 under installation (npm install, import)
- Import Notiflix
import { Confirm } from 'notiflix';
- 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'); } );
- 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.