Skip to content

SetErrors on formControl while hidden (by *ngIf) in template remove errors on control #24755

@CharlBest

Description

@CharlBest

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[x] Bug report  
[ ] Performance issue
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question
[ ] Other... Please describe:

Current behavior

Step 1: (Optional) Type something into input (make it dirty + touched)
Step 2: Execute method on button click. In method:

  • Hide formGroup in template.
  • Make HTTP request.
  • Set formControl error in HTTP request error callback.
  • Show formGroup again in template.

Sorry it's difficult to explain. I think the StackBlitz example will clarify it more.

Expected behavior

The errors set on the form control should still be there (and not null) if the formGroup gets shown again in the template

Minimal reproduction of the problem with instructions

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

What is the motivation / use case for changing the behavior?

You expect the formGroup to hold onto the errors and not remove them.

Environment


Angular version: 6.0.7


Browser:
- [x] Chrome (desktop) version 67.0.3396.99 (Official Build) (64-bit)
- [ ] Chrome (Android) version XX
- [ ] Chrome (iOS) version XX
- [ ] Firefox version XX
- [ ] Safari (desktop) version XX
- [ ] Safari (iOS) version XX
- [ ] IE version XX
- [ ] Edge version XX
 
For Tooling issues:
- Node version: v8.10.0  
- Platform:  Windows  

Others:

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions