question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

hostBinding `class.xxx` can not update after `zone.onStable`

See original GitHub issue

🐞 bug report

Affected Package

possibly to be @angular/core and NgZone

Is this a regression?

this bug is happened in ng8 and ng9

Description

I add host:{'[class.blue]': 'isColorful'} in @Component, and in lifeCycleHooks like ngOnInit or ngAfterViewInit or ngAfterContentInit i update the property isColorful like

   this._zone.onStable.asObservable().pipe(take(1)).subscribe(() => {
     this.isColorful = true;
   });

and the view was not updated, if not use zone.onStable, it works ok.

🔬 Minimal Reproduction

https://stackblitz.com/edit/angular-bb6xlp

🔥 Exception or Error

code:

image

the expected view :

image

current view:

image

I expect when trigger zone.onStable to update the hostBinding property, the view will be update too.

🌍 Your Environment

Angular CLI: 9.0.0-rc.7 Node: 10.18.0 OS: win32 x64

Angular: 9.0.0-rc.7 … animations, cli, common, compiler, compiler-cli, core, forms … language-service, platform-browser, platform-browser-dynamic … router Ivy Workspace: Yes

Package Version

@angular-devkit/architect 0.900.0-rc.7 @angular-devkit/build-angular 0.900.0-rc.7 @angular-devkit/build-optimizer 0.900.0-rc.7 @angular-devkit/build-webpack 0.900.0-rc.7 @angular-devkit/core 9.0.0-rc.7 @angular-devkit/schematics 9.0.0-rc.7 @ngtools/webpack 9.0.0-rc.7 @schematics/angular 9.0.0-rc.7 @schematics/update 0.900.0-rc.7 rxjs 6.5.3 typescript 3.6.4 webpack 4.41.2

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:13 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
pkozlowski-opensourcecommented, Jan 8, 2020

To clarify:

  • this is not a regression (all previous versions behave the same) - currently host bindings, for a given component, are not updated as part of component’s view change detection;
  • longer term we might revisit behaviour of host bindings wrt to calling detectChanges() as I can see how the current behaviour could be confusing…
1reaction
dawidgaruscommented, Mar 27, 2020

@dandean I’m using Renderer2 inside ngDoCheck instead of HostBinding. It introduces little additional boilerplate and actually works when change detection happens for the component:

ngDoCheck(): void {
  bindClass(renderer, element.nativeElement, 'foo', this.classFoo);
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to add "class" to host element? - angular - Stack Overflow
This CSS is defined inside the component and the selector is only applied if the class someClass is set on the host element...
Read more >
Resolved Issues | Release Notes: Junos OS Release 14.2R8 ...
On MX Series platforms with Enhanced DPCs equipped, after router is rebooted, the IRB broadcast channel is not enabled, all the broadcast packets...
Read more >
cannot find module 'rxjs/observable' or its corresponding type ...
It is happening due to the recent changes and the major RXJS upgrade from version 6 to 7. If you upgrade your Typescript...
Read more >
号外:Angular 4 正式版发布!! - 掘金
We've updated Angular to a more recent version of TypeScript. ... common: do not reference deprecated classes in providers (#14523) (#14523) ...
Read more >
Signaling Delivery Controller - User Guide - Document Name
No license is granted by implication or otherwise under any patent, ... Update Editing an SNMPv3_Internal User Profile Editing an.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found