Respond when Angular (re)sets data-bound input properties. The method receives a SimpleChanges object of current and previous property values. Called before ngOnInit and whenever one or more data-bound input properties change.
Questions tagged [ngonchanges]
123 questions
1
vote
1 answer
Angular @Input value not changing when changed from Parent Component
I have added same child component three times in a single parent component
And below is the change function called on one of the children's components to change the selectedName in other two child components
The @Input is type of string if I change…

RS Roshi
- 53
- 1
- 6
1
vote
1 answer
Why is ngOnChange being called twice in a child component with only one input variable
I have a child component that takes one input variable. The child component makes use of ngOnChanges so that any changes to the input variable triggers a change.
Everything is working fine, however, I see that ngOnChanges gets called twice every…

mo_maat
- 2,110
- 12
- 44
- 72
1
vote
1 answer
ngOnChange is not called when the parent updates the child
i want to know how ngOnChanges callback works. so i have added it to observe changes in a prpoperty annotated with Input decorator as follows:
@Input() postsToAddToList: Post[] = [];
now, when I compile the code i add some values that causes change…

Amrmsmb
- 1
- 27
- 104
- 226
1
vote
1 answer
ngOnChanges only hitting root of tree, not all offsprings
My parent component has a non binary tree node(the root of the tree) as child.
Every node can have 0 or multiple children of type node, and the children can be collapsed or expanded.
Additionally, in my parent component, there is button that allows…

Elena O
- 33
- 5
1
vote
1 answer
problems with ngOnChanges when updating an array
I have an array that is getting updated from another component (the update is happening and Strings are getting added into the array I've checked it with a test button) but ngOnChanges wont detect any change. What is wrong with my code?
The change I…

Ni Tai
- 499
- 1
- 7
- 13
1
vote
2 answers
ngOnChanges not triggered though I called ChangeDetectorRef.detectChanges
export class AppComponent implements OnInit, OnChanges {
@Input()
value: number;
constructor(
private cdr: ChangeDetectorRef
) {}
ngOnInit() {
of(1).subscribe(v => {
this.value = v;
console.log(1);
…

critrange
- 5,652
- 2
- 16
- 47
1
vote
4 answers
How to access variables other than @Input params on ngOnChanges in Angular?
I encountered a scenario where i need to do some processing of data on ngOnchanges(as the data is coming through @Input data bound property from parent component). During this transformation i need to use a property initialized in ngOnInit. I tried…

Deadpool_er
- 215
- 4
- 20
1
vote
3 answers
Check if the Enter key has been pressed in the ngOnChanges lifeCycle hook?
I am running Angular 7.x - I have the following ngOnChanges lifeCycle hook and I need to determine if the user has pressed the [ENTER] key and if so pass this boolean value to the processLinks() below as a boolean value - what is the best way to do…

Zabs
- 13,852
- 45
- 173
- 297
1
vote
1 answer
Angular 7: ngOnChanges fires only once
I can't figure out why ngOnChanges only fires once. When initially set.
import { Component, OnInit, Input, SimpleChanges, OnChanges } from '@angular/core';
@Component({
selector: 'app-fixed-decimals-input',
templateUrl:…

yBother
- 648
- 6
- 25
1
vote
1 answer
NgOnChanges overrides form control value when user types
I have autocomplete form control:
@Component({
selector: 'app-autocomplete',
templateUrl: './app-autocomplete.view.html',
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class AutoCompleteFilterComponent implements OnInit,…

Alex Gurskiy
- 346
- 1
- 7
- 20
1
vote
2 answers
ngOnChanges child method is not triggering when attempting to pass a new object
I have a parent page that passes user data to a child component like so:
The parent page ngOnInit()…

Jordan Lewallen
- 1,681
- 19
- 54
1
vote
2 answers
Angular array changes detection
I am a beginner with Angular, and i can't find proper solution for my problem.
I have a component containing table filled with list of items (each item in list is in another component), and there is third component containing filter. Filter contains…

Mystax
- 63
- 1
- 1
- 7
1
vote
1 answer
Angular 6 detect changes to graph
Iam working in angular 6 and Leaflet for mapping. I want to create an interactive map that changes view based on the property selected in my form.
I have set the condition to draw the graph in ngOninit but the condition only works when the…

Newbiiiie
- 1,401
- 3
- 14
- 33
1
vote
1 answer
ngOnChanges is not triggered
Hello i am new to angular and having a little issue, here is my code :
import { Component, OnInit,Input, SimpleChange, OnChanges } from '@angular/core';
import { Sensor } from '../../shared/sensor.model';
import { MessageService } from…

FrozzenFinger
- 1,482
- 2
- 14
- 35
1
vote
1 answer
ngOnChanges fires nonstop and makes application not to repond
I built a component with the name of "gw-responsive-tabs" that has an input with variable (navLinks) which is an Array of the tabs I want to display. When I deliver the input data from the html like that:

Udi Mazor
- 1,646
- 2
- 15
- 30