Angular2: Unsubscribe from host listener [duplicate]
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: This question already has an answer here: Programmatically (un)register to event with Angular 2 2 answers If I subscribe to an event in an Angular2 component using host{}, how can I unsubscribe from the event? @Component({ selector: "foo", host: { "(window:resize)": "doSomething($event)" } }); I've tried to use $event to unsubscribe, but the event itself never presents the scenario in which I want to unsubscribe. For now, I'm just doing a poor man's short circuit, but I'd prefer to avoid the extra checks involved in short circuiting. Poor