I want to change the appearance of my navbar whenever the scroll is not at the top.
I'm using Angular Material CdkScrollable and I'm successfully retrieving the scroll Event which gives me the data about how far it is to the top.
The issue I have is that the CSS classes never changes when I scroll. I'm verifying with a console.log that the variable isScrolled is updated properly whenever I scroll down and up to the top again. So that seems to work OK. I'm using a ngClass with a ternary to validate which CSS class that should apply.
Something obvious that I'm missing?
html
<nav [ngClass]="isScrolled ? 'navbar-desktop-scrolled' : 'navbar-desktop'">
   ...
</nav>
ts
export class MainNavComponent implements AfterViewInit {
 @ViewChild(MatSidenavContainer, { static: false }) sidenavContainer: MatSidenavContainer;
 isScrolled: boolean = false;
 ngAfterViewInit() {
    this.sidenavContainer.scrollable.elementScrolled().subscribe((x) => {
      if ((<Element>x.target).scrollTop > 0) {
        this.isScrolled = true;
      } else {
        this.isScrolled = false;
      }
      console.log(this.isScrolled);
    })
  }
}
    
MatSidenavContainerbut on thehostelement, so no scroll event is fired. Also there is notargetproperty onx. The result is simply{isTrusted: true}.