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.

ngClass/ngStyle are evaluated before exported directives

See original GitHub issue

🐞 bug report

Affected Package

@angular/core 8.x

Is this a regression?

The behaviour seemed different in Angular 6 (7 was never testet). Hard to say because a refactoring to onPush strategy was made simultaniously. Sorry for that.

Description

I used to have a little helper directive which caches values inline in the template by using the exportsAs technique. This directive only holds a value property, is selected via “store-value” attribute and exports as “store”. The usage is as follows:

<div #metaInfoStore=store [store-value]="getItemMeta(item)">{{metaInfoStore.value.name}} {{metaInfoStore.value.description}}</div>

Simple and works like a charm without having to implement anything in ngDoCheck(). The issue starts when i use the store value within class bindings (ngClass).

<div #metaInfoStore=store [store-value]="getMeta()" [ngClass]="{'locked': metaInfoStore.value.locked}">{{metaInfoStore.value.name}} {{metaInfoStore.value.description}}</div>

When using the onPush change detection strategy, the ngClass directive is evaluated BEFORE the store directive is. I did not change any of my code, but updated to angular 8 and set change detection strategy to OnPush.

🔬 Minimal Reproduction

https://stackblitz.com/edit/angular-1xr6cb The div Element should receive the ‘locked’ class which it doesn’t.

Thanks in advance.

Issue Analytics

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

github_iconTop GitHub Comments

2reactions
karacommented, Feb 4, 2020

@mhevery From what I can tell, it looks like @Andy1605 is trying to file a bug report about Angular 8, which is View Engine by default. I don’t think this is an Ivy issue.

0reactions
angular-automatic-lock-bot[bot]commented, Nov 19, 2020

This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Angular ngClass and ngStyle: The Complete Guide
The ngClass directive will take an expression that will be used to determine which state styles to apply at a given time to...
Read more >
Angular 14 NgClass and NgStyle Tutorial with Examples
Here in this article, we are going to take a closer look at class bindings. Moreover, we will be examining Angular NgClass directive...
Read more >
NgStyle & NgClass • Angular - codecraft.tv
The NgStyle directive lets you set a given DOM elements style properties. One way to set styles is by using the NgStyle directive...
Read more >
What does putting [ngClass]="class"and [ngStyle]="style" do to ...
The ngClass attribute allows a string (list of classes as space-delimited string), array of strings (list of classes) or object (with the ...
Read more >
NgClass - Angular
The CSS classes are updated as follows, depending on the type of the expression evaluation: string - the CSS classes listed in the...
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