AlexMiniApps/angular-code-input

Assigning value to code programatically not working after first time.

Closed this issue · 6 comments

If you assigned value for the first time it works.
But the second time its not.

this.code = '1111'; // works
... some code ...
this.code = '2222' // doesn't work

I found a workaround, but still i think its need a fix.
this.code = '1111'; // works
... some code ...
this.code = '2222'
setTimeout(() => this.code = '2222' // works

But this workaround only works if the previous value of code wasn't empty string.
this.code = '1111'; // works
... some code ...
this.code = ''
setTimeout(() => this.code = '2222' // doesn't works

But if we assigned undefined it works
this.code = '1111'; // works
... some code ...
this.code = undefined
setTimeout(() => this.code = '2222' // works

@moshe5745 Hi. ok. I will add the fix for that.

@moshe5745 I have checked the current version of the lib and it works as expected. I have used the latest version '1.2.2'.
You can check it by yourself:

  1. Unpack the attached archive
    test-app-copy.zip

  2. From the project folder run npm install

  3. From the project folder run ng serve

In your code please check that the value is changed during different browser events loop. If the changing will be in the same event loop the last value for the current loop will be used. Also please ensure that you use the latest lib version

Example 1 with the same evet loop:

... some sync  code ...
this.code = 1234
... some sync  code ...
this.code = 5555

The last value will be shown in the component - 5555

Example 2 with the different event loops:

... some sync code ...
this.code = 1234
... some sync  code ...
this.code = 5555
... some sync  code ...
setTimeout(() => this.code = 7777) // will be called async in the next loop

The last value for the latest event of the browser will be shown in the component - 7777

I downloaded and ran your code and its working properly.
Maybe its because i use ionic app, and not just angular.

@moshe5745 I have also checked the lib on the Ionic. Please check the attachment, it is the Ionic project.
blank-copy.zip

@moshe5745 Have you solved the issue?

Closing as not reproducible