I am trying to apply a thick shadow to the toolbar when the user scrolls. I see scrollOffsetTop
change in the console, but ngClass
is not detecting the change and applying the class heavy-shadow
when the value is greater than 0.
Why is ngClass not detecting the change?
<mat-toolbar [ngClass]="{'heavy-shadow': scrollTopOffset > 0, 'toolbar': true }">
export class AppComponent implements AfterViewInit {
@ViewChild('snav') public snav: MatSidenav;
@ViewChild('sideNavContent') public sideNavContent: MatSidenavContent;
mobileQuery: MediaQueryList;
private _mobileQueryListener: (media) => void;
@Input()
public scrollTopOffset:Number = 0;
constructor(
private changeDetectorRef: ChangeDetectorRef,
private media: MediaMatcher) {
this.mobileQuery = this.media.matchMedia('(max-width: 1000px)');
}
runScroller() {
const scroller = this.sideNavContent.elementScrolled();
scroller.subscribe({
next: () => {
this.scrollTopOffset = this.sideNavContent.measureScrollOffset('top');
console.log(this.scrollTopOffset); // THIS CHANGES SUCCESSFULLY, I VERIFIED IN CONSOLE
},
error(msg) {
console.log(msg);
},
});
}