Listening to an event in Dart via jQuery "on"
I am using Bootstrap Modal dialog in Dart via js interop. Everything works fine except listening for custom events. I am trying to listen to the "shown" event using the following code:
js.scoped(() {
js.context.jQuery("#myModal").on("shown", new js.Callback.once(() {
print("Dialog Shown");
}));
});
However, I am getting the following Dart error when the event is fired:
Class '() => dynamic' has no instance method 'call'.\n\nNoSuchMethodError : method not found: 'call'\nReceiver: Closure: (dynamic) => dynamic\nArguments: [Instance of 'Proxy']
Any ideas what I am doing wrong?
Thank.
source to share
You are getting this error because the callback must have one parameter ( the docon
parameter takes a parameter eventObject
). Therefore, your code should be:
js.context.jQuery("#myModal").on("shown", new js.Callback.many((eventObject) {
print("Dialog Shown");
}));
Note also the use of js.Callback.many
instead of js.Callback.once
. The first allows the callback to be called multiple times.
source to share