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.

component implements ControlValueAccessor still connected to ngForm after destroy

See original GitHub issue

🐞 bug report

Affected Package

The issue is caused by package @angular/forms

Is this a regression?

I don’t know if this had work before.

Description

When a component implementing ControlValueAccessor is destroyed, writeValue is still called on patchValue for example. Destroy component multiple times results in multiple writeValue called

🔬 Minimal Reproduction

please try this stackblitz, click on [toggle input] button multiple times to create and destroy component and click on patch value button to see in console the console.log from writeValue https://stackblitz.com/edit/angular-pfmvxh

 writeValue(obj: any): void {
    console.log('writeValue', obj);
  }

You should see one writeValue by component destroyed

🔥 Exception or Error

if detection strategyis set to OnPush and call ChangeDetectorRef.detectChanges() in writeValue we will raise a ViewDestroyedError that confirm that writeValue is called even component is destroyed

🌍 Your Environment

Angular Version:


@angular-devkit/architect         0.10.6
@angular-devkit/build-angular     0.10.6
@angular-devkit/build-optimizer   0.10.6
@angular-devkit/build-webpack     0.10.6
@angular-devkit/core              7.0.6
@angular-devkit/schematics        7.0.6
@angular/cdk                      7.1.0
@angular/cli                      7.0.6
@angular/material                 7.1.1

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:14
  • Comments:11 (4 by maintainers)

github_iconTop GitHub Comments

8reactions
MuhammadElhrzcommented, Mar 5, 2020

Is there any fix or workaround for that bug?

6reactions
Airbladercommented, Oct 16, 2019

Guys, the bot only locks already closed issues, it does not close open issues due to inactivity. There’s a bunch of people receiving emails for every comment so I would appreciate if we could keep the comments relevant to the issue and not succumb to spamming it with emojis.

Read more comments on GitHub >

github_iconTop Results From Across the Web

angular - Why writeValue called after detroy component which ...
I solved this problem already. And I want to write why this is happening. Every time when ControlValueAccessor component created, it register ...
Read more >
Understanding Angulars ControlValueAccessor
We do this Because the NG_VALUE_ACCESSOR is binding things to components :host and linking to methods (ControlValueAccessor methods) there.
Read more >
Form validation with ControlValueAccessor
This method is triggered when a value is set on the component either through [ngModel] (template-driven forms) or formControl.setValue(someVal) (reactive forms) ...
Read more >
Working with Angular forms in an enterprise environment
To implement this, use the FormGroupDirective as ControlContainer and provide them via viewProviders (not via providers ). We can now inject ...
Read more >
Building your own form fields the Angular way with control ...
Implementing ControlValueAccessor ... Since everything is ready for Angular to accept our component as a field, we now have to propagate the value ......
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