I have created a simple example to demonstrate a weird issue I\'m facing.
Stackblitz - https://stackblitz.com/edit/angular-change-detection-form-group
I hav
Angular only detects changes if the memory address of the variable changes. Setting the value does not change memory address, thus does not hit ngOnChanges.
Same goes with arrays. A simple push does not hit ngOnChanges, have to change memory address by = to new array.
Try this:
import { Component, Input, OnInit, OnChanges, ChangeDetectionStrategy } from '@angular/core';
import { FormGroup } from '@angular/forms';
@Component({
selector: 'app-input',
template: `
Name : {{form.value.name}}
Age : {{form.value.age}}
`,
styles: [``],
changeDetection: ChangeDetectionStrategy.OnPush
})
export class InputComponent implements OnInit, OnChanges {
@Input() form: FormGroup;
ngOnInit() {
}
ngOnChanges(changes) {
console.log(changes)
}
}