ChangeDetectorRef.markAsUntouched()
See original GitHub issueI’m submitting a…
[x] Feature request
Current behavior
Methods that don’t change anything still trigger change detection. Currently the only way to fix this is to use OnPush or detach(), both of which require modifying the entire component subtree to support OnPush change detection. E.g. A HostListener(‘scroll’) will cause change detection on each scroll, which is expensive.
Expected behavior
Methods should be able to call a method changeDetector.markAsUntouched()
to indicate that the current method has not changed any state. Then, Angular can skip the onLeave change detection if only that method ran.
Minimal reproduction of the problem with instructions
- Create a class like
export class SomeComponent {
aVeryLargeMutableObject = new VeryLargeMutableObject();
@HostListener('window:scroll', [])
onWindowScroll() {
// Do nothing
}
}
- Now, scrolling is very slow because change detection occurs every time.
What is the motivation / use case for changing the behavior?
Allow methods that don’t change anything to run efficiently, without having to modify the whole component tree to use OnPush.
Environment
Angular version: latest Browser: All browsers
Issue Analytics
- State:
- Created 6 years ago
- Comments:6 (5 by maintainers)
Top Results From Across the Web
ChangeDetectorRef - Angular
Base class that provides change detection functionality. A change-detection tree collects all views that are to be checked for changes. Use the methods...
Read more >How to reset reactive Angular Material form in Angular?
I've tried to use this.formdata.reset() . It is resetting the form but it's making it touched . So I used this.formdata.markAsUntouched() ...
Read more >Angular API Manual - Hubwiz.com
NgModule FAQs · What is the forRoot() method? ... Intercept input property changes with ngOnChanges() - Component ... changeDetectorRef · ComponentRef.
Read more >angular/angular - Gitter
So my question is, @Output() parameters use emit() but it does not ... I've tried using NgZone and ChangeDetectorRef but without success.
Read more >Angular 7 Dynamic validators - Medium
markAsTouched() Marks the control as touched. A control is touched by focus and blur events that do not change the value. markAsUntouched()
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
You can also disable parts of zone’s patching globally if performance against these events are an issue:
This is actually provided in newer versions of angular-cli: https://github.com/angular/devkit/blob/1f1c2750a81a9b1397327cc2a3c3cb91d18c340c/packages/schematics/angular/application/files/__sourcedir__/polyfills.ts#L55-L62
This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.