mark
mark

Reputation: 129

Listening for event in Dart via JQuery "on"

I am using a Bootstrap Modal dialog in Dart via js interop. All works OK apart from listening for the 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 get 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'm doing wrong?

Thanks.

Upvotes: 0

Views: 297

Answers (1)

Alexandre Ardhuin
Alexandre Ardhuin

Reputation: 76193

You get this error because the callback should have one parameter (handler parameter of on documentation take a eventObject parameter). So 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 former allows the callback to be called several times.

Upvotes: 1

Related Questions