#Why the cdk-virtual-port elementScrolled() event doesn't change my element style

6 messages · Page 1 of 1 (latest)

chilly jacinth
#

it's so strange, when i click the element outside the virtual port, the style was changed...

gentle terrace
#

idk could be a change detection problem. Try to add private _cdr: ChangeDetectorRefin the constuctor and then call this._cdr.detectChanges();after console.log(this.headerBackground)

#

.
something about clean coding in this line this.scrollEvent$ = this.virtualScroll.elementScrolled().subscribe(data => {
usually the $ suffix is used for obsevables but in this case scrollEvent$ is a subscription (and not an observable).
in my optnion i prefer to call it scrollEventSubscription so it's clear that this is not an observable and you can't subscribe on it

chilly jacinth
gentle terrace
#

yes. You should check if the value has changed and then call detectChanges() so the performance won't be affected.

btw. I was wondering what is [style.--background] ? why not [style.background]? what's the difference?

chilly jacinth