Questions tagged [angular-changedetection]

Used for questions regarding Angular's change detection routines.

As opposed to AngularJS's digest cycles, Angular uses change detection which occurs in zones (see NgZone). Questions regarding this process, how it differs from AngularJS's digest cycle, how microtasks work, etc., are all applicable to this tag.

353 questions
4
votes
1 answer

Angular change detection: how to refresh only certain items?

Let's say I have 100 divs on my screen generated by *ngFor that takes values from my object that has data like {A1: someObject, A2: someOtherObject..., J10: someOtherOtherObject} I click on A1 and then on J10 and they switch their values. It…
4
votes
2 answers

Run Angular change detection only once and stop detecting changes for that component

I need to detect changes in angular only once when the component is loaded or when route has changed and i want to stop detecting changes after that. Actually I need to show and hide functionality depending on user role. So i have many *ngIf in a…
4
votes
2 answers

Angular 8 value won't update on view after change

I have a small component in Angular with a method that (for now) sets a timeout and changes the value of a variable. import { Component, ChangeDetectionStrategy } from '@angular/core'; @Component({ selector: 'my-component', templateUrl:…
4
votes
3 answers

Force change detection in pipe (pure or impure) bound to ngModel

I'm binding an ngModel value to the angular percent pipe, updating on ngModelChange with updateOn set to blur. It works well except when entering the same value again. When entering the same value again, the pipe does not detect the change and the…
4
votes
1 answer

Angular7 Reactive Forms input property value does not change in controller/component, only on the HTML markup

I have made a reusable component that has a reactive form group. I have 2 input properties "name" and "Description" and I am iterating the component with ngFor setting these input properties. Unfortunately, even if I set my start/default value in…
4
votes
0 answers

When loading same component with different data, old data still showing - Angular 5

In an Angular 5 app I am building, I have a side menu and main content menu. Two of the menu items on the left load the same component with different route data. By default, Angular uses the same component instance to render both. Hence, the…
Bill
  • 2,026
  • 9
  • 55
  • 99
3
votes
1 answer

Navigating back causes change detection to break in Angular elements

I am using Angular elements to use my components inside of custom ThingsBoard widgets. The elements are created inside ngDoBootstrap() like this: const newCustomElement = createCustomElement(CustomElementComponent, { injector:…
Chris
  • 1,417
  • 4
  • 21
  • 53
3
votes
2 answers

Why does Angular trigger ChangeDetection on parent components on DOM events despite OnPush strategy?

Trick question I haven't found any answer in the documentation yet. A change detection cycle is triggered when AppRef.tick() is beeing called (mostely by the NgZone patches). It goes from the root component at the top of the tree to the bottom…
Matthieu Riegler
  • 31,918
  • 20
  • 95
  • 134
3
votes
1 answer

Angular: why does view get re-rendered even when change detection detects no change?

Component: @Component({ selector: 'my-app', templateUrl: './app.component.html', styleUrls: [ './app.component.css' ] }) export class AppComponent { //name = 'Angular'; onClick(){ //this.name = 'hey'; } check(){ …
Daud
  • 7,429
  • 18
  • 68
  • 115
3
votes
1 answer

Infinite loop when calling detectChanges() inside ngAfterViewChecked?

I recently reviewed some code where detectChanges() is called from ngAfterViewChecked. How does that not cause an infinite loop? Shouldn't it trigger another change detection cycle, which will call ngAfterViewChecked again? Or does the change…
3
votes
1 answer

Angular change detection vs Svelte change detection

I use Angular for my day job and am learning Svelte on the side. I understand that neither Angular or Svelte use a virtual dom and diffing. I understand that both have other change detection mechanisms, and, from what I've researched, they look…
Barley
  • 143
  • 1
  • 9
3
votes
3 answers

Why to use Subject or BehaviorSubject in services when angular can detect latest values?

For example we have a service that has a list of items in it. When we change this list in the service, all of the components that are using this list will detect this change. for example if you add a new item all of the components will detect it. so…
3
votes
1 answer

Angular ChangeDetectorRef: Cannot read property 'detectChanges' of undefined

I am receiving the following error with ChangeDetectorRef. Not sure why its suddenly occurring, when other components utilize ChangeDetectorRef. Does anyone know how to solve? Its linking to a Kendo Grid selection. TypeError: Cannot read property…
user13885958
3
votes
1 answer

Angular 9 display number of change detection cycles on the UI? stackblitz inside

I'm trying to build a small dev component that displays only in non-production builds. One of the things that I see useful to keep track of is the number of change detection cycles that I'm triggering as I'm adding various functionality to make…
SebastianG
  • 8,563
  • 8
  • 47
  • 111
3
votes
2 answers

Umbraco v8: custom script call model change

I have an Umbraco plugin that is literally a vanilla .js file that allows me to retrieve some JSON from a service, then it fills in some of the fields on the current page, e.g by doing: var setTxt = function(id, val) { var txt =…
Dave
  • 5,283
  • 7
  • 44
  • 66
1 2
3
23 24