Angular: @HostListener and `host` bindings are not working on 3.0.0-alpha+1

Created on 15 Mar 2017  路  5Comments  路  Source: angulardart/angular

After trying to use the annotation @HostListener with an output the code doesn't work:

@Component(selector: 'bs-pagination',
  template: '''
<li *ngFor="let page of pages" [ngClass]="{active: page['active'], disabled: disabled && !page['active']}"
    class="page-item">
  <a class="page-link" href (click)="selectPage(page['number'], $event)">{{page['text']}}</a>
</li>
''')
class BsPaginationComponent {
  ...

  int _currentPage = 1;

  /// gets the index of selected page
  int get currentPage => _currentPage;

  /// sets the index of selected page
  @Input() set currentPage(num value) {
    _currentPage = value ?? 1;
    currentPageChange.emit(_currentPage);
  }

  /// emits that the current page has changed
  @Output() EventEmitter currentPageChange = new EventEmitter();

  @HostListener('currentPageChange', const ['\$event'])
  onCurrentPageChange(currentPage) =>
      pages = getPages(currentPage, totalPages);
...
}
as intended merging

Most helpful comment

I'll take a look tomorrow AM.

All 5 comments

I'll take a look tomorrow AM.

Got delayed, investigating now.

OK, I think I can reproduce. Working on fix.

EDIT: This is WAI. You can't use @HostListener to listen to yourself.

Potential fix for your code:

BsPaginationComponent() {
  currentPageChange.listen(onCurrentPageChange);
}

yes, I'm already doing that thanks.

so @HostListener is not going to work anymore for self component?

Was this page helpful?
0 / 5 - 0 ratings