Registering to Angular 2 component's event from it's native/DOM representation

时间:2018-09-19 08:30:19

标签: javascript angular dom

I have Angular component with event defined like this:

// selector: 'my-component'
export class MyComponent {
    @Output() customEvent = EventEmitter();
}

Later in structural directive I access native Html element of this Angular component:

const view = this.viewContainer.createEmbeddedView(this.templateRef);
const rootElem = view.rootNodes[0];
const myNativeComponent = rootElem.querySelector('my-component');

Now, is there any way to listen on 'customEvent' having only myNativeComponent instance?

// this doesn't work:
myNativeComponent.addEventListener('customEvent', ...) 

0 个答案:

没有答案