Questions tagged [angular2-changedetection]

473 questions
14
votes
1 answer

behaviourSubject in angular2 , how it works and how to use it

I am trying to build a shared service as follow import {Injectable,EventEmitter} from 'angular2/core'; import {Subject} from 'rxjs/Subject'; import {BehaviorSubject} from 'rxjs/subject/BehaviorSubject'; @Injectable() export class SearchService…
Ironsun
  • 801
  • 2
  • 8
  • 19
13
votes
1 answer

Angular 2: ChangeDetection and mousemove event

I have an Angular 2 Component with many children. Because of performance issues, I wanted to check how often the ChangeDetection checks my child-components. So I logged the ngAfterViewChecked-callback of one of my child-components. I realized that…
ant45de
  • 832
  • 1
  • 7
  • 26
13
votes
3 answers

Detect change in child component's variable triggered by parent angular 2

I have 2 files. app.ts and Child.ts I am sending a variable from app to child and I want to detect any change in the variable and show data accordingly. I am not able to detect changes in a variable. Any Help? I have attached Plunker Link and I have…
amansoni211
  • 889
  • 2
  • 13
  • 30
13
votes
2 answers

How to check if Change Detection was triggered on a component

In my app I want to set manual change detection. For this I set the ChangeDetectionStrategry to OnPush and whenever a change occurs in a component I manually run change detection using detectChanges. If I set ChangeDetectionStrategy to OnPush on a…
12
votes
1 answer

What does Angular Ivy specifically allow us to do in regards to manual change detection?

This article mentions that Ivy opens a few possibilities for the future though. It should now be possible to run an application without zone.js, and to semi-manually handle change detection (a bit like you would with React). These APIs already…
Maxime Dupré
  • 5,319
  • 7
  • 38
  • 72
12
votes
1 answer

Angular OnPush: how do I force changes to be detected from outside?

I have a scenario where I have two components sitting alongside each other, ComponentA and ComponentB. They both use a service Service. ComponentB contains a button which will make a property in Service, Service.counter, go up by 1. ComponentA…
Bart van den Burg
  • 2,166
  • 4
  • 25
  • 42
12
votes
2 answers

Angular 5.0 change detection strategy VS React's change detection strategy

I understood how change detection works in Angular 5.0. Can some one help me to understand how the same works in React and how much it was different from Angular's ?
kalki
  • 465
  • 7
  • 14
11
votes
3 answers

Expression has changed after it was checked - MatDialog Angular 6

I have read several answers, and I have tried many but I can't seem to get this to work. In my angular 6 app, I try to open a MatDialog but I receive this error: ERROR Error: ExpressionChangedAfterItHasBeenCheckedError: Expression has changed…
Michael
  • 3,093
  • 7
  • 39
  • 83
10
votes
1 answer

Change Detection works intermittently when receiving data from Electron Container IPC Channel

I have an application that is listening for incoming data from an IPC Renderer Channel. Here is my setup: container that sends data to angular app (mainWindow): mainWindow.loadURL('http://www.myangularapp.com') //where the angular app lives (example…
Kode_12
  • 4,506
  • 11
  • 47
  • 97
10
votes
2 answers

@HostListener cause change detection triggers too many times when I'm listening for outside click

I have next template of root component, that draws 9 tiles:
and next tile component, where I added HostListener for document click: import {AfterViewChecked,…
Artem
  • 691
  • 5
  • 20
10
votes
4 answers

Would you recommend ChangeDetectionStrategy.OnPush as default changeDetection in Angular 2?

Would it be a reasonable convention within an Angular-2 project to always use changeDetection: ChangeDetectionStrategy.OnPush within a component's decorator? Except when there are clear reasons to use the default-strategy?
Martin Cremer
  • 5,191
  • 2
  • 32
  • 38
10
votes
2 answers

How to reuse the elements of ngFor even if the list reference changes?

I have an Angular 2 component that uses *ngFor to render a nested array of numbers. @Component({ selector: 'app', template: `
danijar
  • 32,406
  • 45
  • 166
  • 297
9
votes
2 answers

Angular: Change in Pipe not detected

I have this pipe which multiplies the input value by an other value retrieved from a service: @Pipe({ name: 'multiply' }) export class MultiplyPipe implements PipeTransform { constructor(private service: StateService) { } …
Jeanluca Scaljeri
  • 26,343
  • 56
  • 205
  • 333
9
votes
2 answers

Angular - Is binding a component method to DOM target property a wrong practice?

Say, I have a component which is used as following: After reading data-binding related parts from https://angular.io/guide/template-syntax, it seem like the…
Uthman
  • 9,251
  • 18
  • 74
  • 104
9
votes
1 answer

Angular ngDoCheck() gets called even with ChangeDetectionStrategy.OnPush

Lets say i have a component structure like this: AppComponent HeaderComponent ContentComponent TodosComponent TodoComponent If I set HeaderComponent's changeDetection to ChangeDetectionStrategy.OnPush and change…
Mick
  • 8,203
  • 10
  • 44
  • 66
1 2
3
31 32