Skip to content

Commit

Permalink
refactor(directive): signals
Browse files Browse the repository at this point in the history
  • Loading branch information
bartholomej committed Jun 14, 2024
1 parent 0b108d1 commit a1e9492
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions projects/ngx-scrolltop/src/lib/ngx-scrolltop.directive.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Directive, ElementRef, HostListener, Input, signal } from '@angular/core';
import { Directive, ElementRef, HostListener, inject, input, signal } from '@angular/core';
import { NgxScrollTopCoreService } from './ngx-scrolltop.core.service';
import { NgxScrollTopMode } from './ngx-scrolltop.interface';

Expand All @@ -8,20 +8,20 @@ import { NgxScrollTopMode } from './ngx-scrolltop.interface';
providers: [NgxScrollTopCoreService],
})
export class NgxScrollTopDirective {
@Input('ngxScrollTopMode') public mode: NgxScrollTopMode = 'classic';
public mode = input<NgxScrollTopMode>('classic', { alias: 'ngxScrollTopMode' });

private show = signal(false);

constructor(
private el: ElementRef,
private core: NgxScrollTopCoreService,
) {
private el = inject(ElementRef);
private core = inject(NgxScrollTopCoreService);

constructor() {
this.hideElement();
}

@HostListener('window:scroll')
public onWindowScroll(): void {
const show = this.core.onWindowScroll(this.mode);
const show = this.core.onWindowScroll(this.mode());

// Performance boost. Only update the DOM when the state changes.
if (this.show() !== show) {
Expand Down

0 comments on commit a1e9492

Please sign in to comment.