Why, using @HostListener, keypress event fires a number of time equal of the times the page is visited (ionic2/typescript)?
问题 I have a page in ionic 2 and I want to catch key pressed when the user is in the page. This is the code I used to do this (.ts) @Component({ selector: 'page-play', templateUrl: 'play.html' }) export class PlayPage { @HostListener('document:keypress', ['$event']) handleKeyboardEvents(event: KeyboardEvent) { console.log("keypressed!"); } constructor() { // doing a lot of things } } Unfortunately, the handleKeyboardEvents gets fired once the first time I enter in the page, twice if, after that,