Last active
September 1, 2021 17:06
-
-
Save matheusmurta/c50d3001664e2353f0bf9908eb8c9298 to your computer and use it in GitHub Desktop.
Directive to detec end of scroll angular material
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Directive, HostListener, Output, EventEmitter } from '@angular/core'; | |
@Directive({ | |
selector: '[scrollTracker]', | |
}) | |
export class ScrollTrackerDirective { | |
@Output() scrolled = new EventEmitter<any>(); | |
@HostListener('scroll', ['$event']) | |
onScroll(event) { | |
const tracker = event.target; | |
let endReached = false; | |
const limit = tracker.scrollHeight - tracker.clientHeight; | |
if (event.target.scrollTop === limit) { | |
endReached = true; | |
} | |
this.scrolled.emit({ | |
pos: event.target.scrollTop, | |
endReached | |
}); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
updateScrollPos(event) { | |
if (event.endReached) { | |
this.filtrar(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<mat-table class="table-responsive fit-table-content" #table matSort | |
[dataSource]="tableHelper.getDadosResults()" scrollTracker (scrolled)="updateScrollPos($event)" | |
(matSortChange)="sortData($event)"> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import on @NgModule({ declarations: [..] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment