Angulardart components - dispatching custom events

I want to send a custom event from my Angular Dart component to the parent. How can I do this with Angular Dart?

In other words, I want to do something similar to this: How do you dispatch and listen to custom events in Polymer?

+2


source to share


1 answer


Maybe emit

does what you want, but I guess it only works in Angular. If you want to dispatch DOM events, you can do so with a method dispatchEvent

like

Element e; // assigned by the injector through a constructor argument or aquired by querySelector, ...
...
var event = new CustomEvent(
  type, /* 'myeventname'
  canBubble: canBubble != null ? canBubble : true,
  cancelable: cancelable != null ? cancelable : true,
  detail: {'somekey', 'someValue'}
);
e.dispatchEvent(event);

      

You can listen to this event at



e.on['myeventname'].listen((e) => print(e.details['somekey']));

      

or in Polymer (because I saw you try to make Angular work alongside Polymer)

<some-element on-myeventname="{{myEventHandler}}"></some-element>

      

+4


source







All Articles