Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clear item after selected, In Version 7.0.0-RC3, it works fine #3021

Closed
lkhuoch opened this issue Mar 4, 2019 · 14 comments
Closed

Clear item after selected, In Version 7.0.0-RC3, it works fine #3021

lkhuoch opened this issue Mar 4, 2019 · 14 comments
Assignees

Comments

@lkhuoch
Copy link

lkhuoch commented Mar 4, 2019

Reproduction link

https://stackblitz.com/edit/nz700?file=src%2Fapp%2Fapp.component.ts

Steps to reproduce

Note: I want clear the select option after selected item, in version 7.0.0-RC3 it worked fine

  1. select item from selected list, it does not clear after select it
  2. If we click on "Reset Product", it clears perfectly
  3. I use the same code with "Reset Product" to clear specific form, but it does not work
  4. In Version 7.0.0-RC3, I used this code to clear it after selected "this.form.setControl('product', new FormControl());"
  5. Please, help me! I put code in app.component.ts

What is expected?

I want it works like previous version.

What is actually happening?

It does not clear after selected from select list with same code in previous version 7.0.0-RC3 and version 7.0.0

Environment Info
ng-zorro-antd 7.0.0
Browser Latest Chrome
@vthinkxie
Copy link
Member

Hi @lkhuoch , are you sure that the codes work fine in 7.0.0-rc.3?
https://stackblitz.com/edit/nz700-xn38t6?file=src%2Fapp%2Fapp.component.ts
here is the reprolink of 7.0.0-rc.3

@lkhuoch
Copy link
Author

lkhuoch commented Mar 4, 2019 via email

@lkhuoch
Copy link
Author

lkhuoch commented Mar 4, 2019 via email

@vthinkxie
Copy link
Member

hi @lkhuoch
I checked from 0.7.1 version to 7.0.0-rc.3 version, all versions before can not work

this.form.setControl('product', new FormControl())

plz check the link above

@lkhuoch
Copy link
Author

lkhuoch commented Mar 4, 2019 via email

@lkhuoch
Copy link
Author

lkhuoch commented Mar 5, 2019 via email

@vthinkxie
Copy link
Member

@lkhuoch
plz check it again, reset form with the code below

this.form.setControl('product', new FormControl());

would not work in 7.0.0-rc.3 in your repro link

@lkhuoch
Copy link
Author

lkhuoch commented Mar 5, 2019 via email

@vthinkxie
Copy link
Member

vthinkxie commented Mar 5, 2019

yes, this.form.setControl('product', new FormControl());
is and was not worked in any before versions.

It could never work in any before versions, including 7.0.0-rc.3 version
not only in latest version.

there is no method to watch set event new FormControl, so there is no way to reset the value when set new FormControl to the component.

@lkhuoch
Copy link
Author

lkhuoch commented Mar 5, 2019 via email

@vthinkxie
Copy link
Member

kapture 2019-03-05 at 11 44 40

Version 7.0.0-RC3:
https://stackblitz.com/edit/nz700-rc3

can not work as what you say.

@lkhuoch
Copy link
Author

lkhuoch commented Mar 5, 2019 via email

@vthinkxie vthinkxie reopened this Mar 5, 2019
@lkhuoch
Copy link
Author

lkhuoch commented Mar 5, 2019 via email

@vthinkxie
Copy link
Member

Hi @lkhuoch
the clicked option has the highest priority in the latest version, so when you click an option, it is impossible to reset it to null again in the same detect change.
but you can do a little trick to hack this with Promise.resolve().then()
here is the demo, I hope this could help you.
https://stackblitz.com/edit/nz700-2vokoh?file=src/app/app.component.ts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants