dolanmiu / ng-color

Simple Angular color picker components which follow Angular best practices. No Frills.
https://stackblitz.com/edit/ng-color-demo
12 stars 6 forks source link

StartHex - ExpressionChangedAfterItHasBeenCheckedError #6

Closed kareljuricka closed 6 years ago

kareljuricka commented 7 years ago

In some cases when using startHex - seems like it depend on color - I got that error - ERROR Error when ngColor picker is displayed - ExpressionChangedAfterItHasBeenCheckedError: Expression has changed after it was checked. Previous value: '#897A7A'. Current value: '#8A7B7B'.

The value I use in startHex is 897A7A but ngColor module recalculates it to 8A7B7B and then trigger that error message.

I noticed that also colorChange event is called twice.

I'm using color property binding with [startHex]="colorVariable". When I add directly some string to startHex property, the error does not appear.

dolanmiu commented 7 years ago

Can you give some steps to reproduce the error?

Did you change the value not with the color picker, but via some other method, then the color picker got confused? Is this what you mean?

kareljuricka commented 7 years ago

I'm passing to color picker value from variable. I don't change value of that color outside. But when I use color e.g. #897A7A , some algorithm in your module changed it to #8A7B7B (without any action with mouse etc.). Outside I catching that colorChange event, and there I set that variable to new value and I noticed there that initial color is not same as startHex - actually two triggers of colorChange event are called, first with startHex color, second with 'algorithm' changed color.

dolanmiu commented 7 years ago

do you use ng-color-picker or ng-color-picker-preview?

kareljuricka commented 7 years ago

ng-color-picker

dolanmiu commented 7 years ago

Could you do me a favour and reproduce it in a Plunkr? I tried to reproduce it just now with #897A7A and it works fine for me.

This would greatly help me find the source of the problem 😭

Thanks!

Edit: colorChange() fires once for me per click also, not twice

dolanmiu commented 7 years ago

@kareljuricka I have made a Plunkr for you so you can reproduce this:

http://plnkr.co/edit/N2VKBCrNNIwInwI8PVOu?p=preview

Let me know if you still have any troubles.

Thanks!

kareljuricka commented 7 years ago

It's interesting that when I use that 897A7A color in plunker, it's not changed to 8A7B7B. I found a way to simulate that error when I set that startHex to undefined. It's same error, but here with change from undefined to a specific color.

Check console log here - http://plnkr.co/edit/pwTaZ1ZcY95DwtcIgFV8?p=preview

dolanmiu commented 6 years ago

Seems to be fixed in 4.1.0, closing!

http://plnkr.co/edit/cg8zs7aQjKSsAt7Cpw6j?p=preview