Does the Ionic3 ngClass binding style need to be triggered by a click?

originally intended to use the ionScroll event in < ion-content > of Ionic3 to change the style of < ion-header > , but the event started with the style unchanged. But if I add a button to header, the style changes with one click.

related codes

HTML

<ion-header [ngClass]="{"transparent-header": transparentHeader}">
  <ion-navbar color="light">
    <ion-title></ion-title>
    <ion-buttons end>
      <button icon-button (click)="goToEdit()"></button>
    </ion-buttons>
  </ion-navbar>
</ion-header>
<ion-content (ionScroll)="scrollEvent($event)"></ion-content>

TypeScript

transparentHeader: boolean = true;

scrollEvent(ionContent) {
  let opacity = 1 - (150 - ionContent.scrollTop) / 150;
  this.transparentHeader =  opacity >= 1 ? false : true;
}

goToEdit() {
  console.log("Go to edit.")
}

originally expected the page to slide down a certain distance, the transparent-header style of header will be automatically removed, but now you have to slide down and click the edit button to remove it, while the edit button contains only one statement output from the console.

Picture

No downward sliding effect is shown in the following figure:

clipboard.png

:

clipboard.png

:

clipboard.png

Apr.01,2021

just read the official documents and found a solution.

Scroll events happen outside of Angular's Zones. This is for performance reasons. So if you're trying to bind a value to any scroll event, it will need to be wrapped in a zone.run ()
Menu