我想从我的Angular Dart组件向他的父组件发送自定义事件。我怎么能用Angular Dart做到这一点?
换句话说,我想做类似的事情:How do you dispatch and listen for custom events in Polymer?
答案 0 :(得分:4)
也许emit
做了你想要的,但我认为这只适用于Angular。
如果您想发送DOM事件,可以使用dispatchEvent
方法(如
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);
您可以通过
收听此活动e.on['myeventname'].listen((e) => print(e.details['somekey']));
或在Polymer中(因为我看到你试图让Angular与Polymer一起工作)
<some-element on-myeventname="{{myEventHandler}}"></some-element>