Listening to event in Dart via jQuery "on" with dart: js

I am using a boottrap callback modal and I want to register a callback function but found the same problem by another person mentioned earlier.

here's the jQuery code:

$('#myModal').on('hidden.bs.modal',function (e) {....})

      

How can I write the same code in a dart with dart:js

because it is package:js

deprecated; so I cannot use the callback function.

Thank you so much!

+3


source to share


1 answer


This should work

import 'dart:js' as js;
...
void someCallback(e) {
  print('callback called, passed: $e');
}
...
js.context.callMethod(r'$', ['#myModal'])
    .callMethod('on', ['hidden.bs.modal', someCallBack]);

      



or

...
js.context.callMethod(r'$', ['#myModal'])
    .callMethod('on', ['hidden.bs.modal', (e) {
        print('callback called, passed: $e');
}]);

      

+2


source







All Articles