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.

NgForm renders form controls slower than expected

See original GitHub issue

🐞 bug report

Affected Package

The issue is caused by package @angular/forms

Is this a regression?

No

Description

Unable to access controls object of NgForm when Angular starts rendering component

πŸ”¬ Minimal Reproduction

If you access the controls object of NgForm like this: image

When Angular starts rendering my component, it said that there’s no such properties like i have in my form controls: image

I console.log() the controls of NgForm, at first, it has nothing like you guys see an empty object in my console, but then chrome developer tool tells β€˜Value below was evaluated just now’. Does that mean when Angular starts rendering my component and access the form controls, the form controls haven’t been there yet?

πŸ”₯ Exception or Error

image





🌍 Your Environment

Angular Version:

Angular CLI: 10.0.6
Node: 12.16.3      
OS: win32 x64      

Angular: 10.0.9
... animations, common, compiler, compiler-cli, core, forms
... platform-browser, platform-browser-dynamic, router
Ivy Workspace: Yes

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.1000.6
@angular-devkit/build-angular     0.1000.6
@angular-devkit/build-optimizer   0.1000.6
@angular-devkit/build-webpack     0.1000.6
@angular-devkit/core              10.0.6
@angular-devkit/schematics        10.0.6
@angular/cli                      10.0.6
@ngtools/webpack                  10.0.6
@schematics/angular               10.0.6
@schematics/update                0.1000.6
rxjs                              6.5.5
typescript                        3.9.7
webpack                           4.43.0



Anything else relevant?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
jnizetcommented, Aug 16, 2020

As far as I understand it, here’s what happens, chronologically:

  • The change detection happens for the app component
  • As part of this change detection, the expressions in its template are evaluated. That fails because f.controls doesn’t contain the child controls yet.
  • If the previous step didn’t fail, then the change detection would then be triggered for the directives and components used inside the template.
  • As part of these change detections, the ngOnChangesmethod of the child ngModel directives would be called, and that’s what would register the child controls into their parent NgForm directive.
1reaction
AndrewKushnircommented, Aug 15, 2020

Hi @anphamv, thanks for reporting this issue. However, you didn’t provide sufficient information for us to understand and reproduce the problem. Please check out our submission guidelines to understand why we can’t act on issues that are lacking important information. Could you please provide a repro using Stackblitz so that we can have a look? Thank you.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why is Angular Form very slow within MatDialog component?
I've tried refactoring the form to use for the inputs to use a "Material form" but still has the same slowdown performance. Here's...
Read more >
Introduction to forms in Angular
Reactive forms and template-driven forms have different levels of reliance on rendering the UI to perform assertions based on form control and form...
Read more >
Testing complex forms - Testing Angular
How to test the logic and accessibility of Angular Reactive Forms.
Read more >
Angular Reactive Forms: Tips and Tricks | by Netanel Basal
There might be cases when we don't want to invalidate the form just because a single control is invalid. I haven't come across...
Read more >
Angular Template Driven vs. Reactive Forms | Syncfusion Blogs
As the form keeps growing, the view templates get cluttered, making the code difficult to read. Thus, it gets harder to maintain, resulting...
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