angulardart components - dispatch custom event

天涯浪子 提交于 2019-12-24 00:52:17

问题


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

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


回答1:


Maybe emit does what you want but I assume this works only within Angular. If you want to send DOM events you can do it with dispatchEvent method 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 for this event by

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

or in Polymer (because I saw that you tried to make Angular work together with Polymer)

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


来源:https://stackoverflow.com/questions/25842440/angulardart-components-dispatch-custom-event

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!