Angular scroll directive not firing

I would like to get a console.log() once the scrollbar in the dropdown reaches bottom to implement infinite scrolling / “load more” feature:

On the code below, I created a ScrollEndDirective directive which will just emit to component file:

export class ScrollEndDirective {
  @Output() scrolledToEnd = new EventEmitter<boolean>();

  constructor(private el: ElementRef) {
    console.log('constructor logger'); // <- this is logging
  }

  @HostListener('scroll', ['$event'])
  onScroll(event: Event): void {
    const element = this.el.nativeElement as HTMLElement;
    console.log(element); // <-- this is not even logging

    if (element.scrollHeight - element.scrollTop === element.clientHeight) {
      this.scrolledToEnd.emit(true);
    } else {
      this.scrolledToEnd.emit(false);
    }
  }
}

below is the component file:

@Component({
  selector: 'nz-demo-auto-complete-options',
  template: `
    <div class="example-input">
      <input
        placeholder="input here"
        nz-input
        [(ngModel)]="inputValue"
        (input)="onInputChange($event)"
        [nzAutocomplete]="auto"
      />
      <nz-autocomplete #auto scrollEnd (scrolledToEnd)="onScrollEnd($event)">
        <nz-auto-option *ngFor="let option of options" [nzValue]="option.name">{{ option.name }}</nz-auto-option>
      </nz-autocomplete>
    </div>
  `,
})
export class NzDemoAutoCompleteOptionsComponent {
  inputValue?: string;
  options: string[] = [];
  private searchSubject = new Subject<string>();

  constructor(private http: HttpClient) {
    this.searchSubject
      .pipe(
        // debounceTime(1000), // debounce for 1 second
        switchMap((value) => this.search(value))
      )
      .subscribe((options) => {
        this.options = options;
      });
  }

  onInputChange(event: Event): void {
    const value = (event.target as HTMLInputElement).value;
    this.searchSubject.next(value);
  }

  search(value: string) {
    return this.http
      .get<string[]>('https://jsonplaceholder.typicode.com/users')
      .pipe(map((response) => response));
  }

  onScrollEnd(atEnd: boolean): void {
    console.log('Scrollbar is at the end');
  }
}

As you can see, directive is added to component nz-autocomplete. It is a ng-zorro Autocomplete component (https://ng.ant.design/components/auto-complete/en).

Reason why I decided not to use ng-zorro’s Select where infinite loading is directly built-in to it:

  • I don’t like the input to display NotFoundContent when user clicks and empty input field. If no input value, just focus on input and show nothing (how ng-zorro’s Autocomplete works). I would like to only display it when there are no actual results.

enter image description here

  • I want the currently selected/inputted text to retain on the field. In ng-zorro’s Select, whenever user selected, you cannot delete previously inputted text. In image below, I want to clear the “apple” text but it does not allow me to as it becomes a placeholder now

enter image description here

I would also appreciate if you can help me tweak ng-zorro’s Select to my liking if its easier. Thank you.

Stackblitz link to my repo: https://stackblitz.com/edit/angular-awrmdb-4dhtrr

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật