Questions tagged [ngonchanges]

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.

123 questions
43
votes
3 answers

Why angular 2 ngOnChanges not responding to input array push

My angular application stuck with a issue, i used input as array and pushed a value to the array when the click event arise. But the ngOnChanges not firing when the array push is done. Is there a way to fire ngOnChange My Code is ts file…
Manush
  • 1,852
  • 7
  • 26
  • 39
9
votes
5 answers

What is the difference between Angular ngOnInit() and ngOnChanges()?

Angular provides lifecycle hook ngOnInit() and ngOnChanges() by default. Why should ngOnInit be used, if we already have a ngOnChanges? And constructor also.
Chanaka Amarasinghe
  • 3,489
  • 11
  • 26
  • 38
8
votes
4 answers

Type checking for SimpleChanges interface in ngOnChanges hook

It would be great if we had type checking inside the SimpleChanges typescript parameter of ngOnChanges hook for the current Component. This would prevent us from errors in the properties we check.
7
votes
1 answer

Angular 4 @Input property update does not affect the UI

There are 2 components: parentComponent and ChildComponent, which is defined inside the parent. In the parentComponent there is a local variable which is used as value to pass to an input property of the ChildComponent (using a…
Batsheva
  • 659
  • 4
  • 13
  • 27
6
votes
0 answers

Angular input change detection performance with mat table data source

Does anyone know if updating a mat table data source in the ngOnChanges lifecycle hook is ok? Or is there a potential data leak or performance concern at scale? Here is a simple example of what I mean. A child component has a parent component that…
5
votes
1 answer

Angular 4 Data in Service, passing to component(s)

Have some data in a service, and was working perfectly when I had data in an object sitting on the service, but now that I've hooked up a database connection, the data never makes it to the component. I want the service to subscribe to the data…
Chris Rutherford
  • 1,592
  • 3
  • 22
  • 58
4
votes
3 answers

Detect internal change to @Input property angular 4

I understand that ngOnChanges is fired when a components @Input property from its parent component. But how I can detect if an @Input property is changed within its component. I've not been able to find a good answer to that. Thanks
Lazloman
  • 1,289
  • 5
  • 25
  • 50
4
votes
2 answers

Function ngOnChanges() is not working in Angular 5

I'm trying to call function ngOnChanges() in my Angular 5.x component whenever the variable this.test in component lifecycle or in template is changed but it's not working, ngOnChanges() function is not called anytime. Please can someone help…
Jan Elznic
  • 189
  • 1
  • 1
  • 8
4
votes
0 answers

Angular 4: NgOnchanges doesn´t work, previousValue is always undefined

I'm using ngOnChanges for to detect de current value and previous value of "idCopiadora" property. When i asked for de currectValue always return de current value, that is ok but the previous value always returns undefined I can not see what is…
ararb78
  • 1,137
  • 5
  • 19
  • 44
4
votes
2 answers

Angular ngOnChanges not updating view

TL;DR: ngOnChanges shows that changes are being detected on an input property, but the view is not being updated I'm working on an Angular (2+) app trying to make a progress bar for an asynchronous task being fulfilled by a service using an…
slander
  • 111
  • 1
  • 7
3
votes
2 answers

Update view on ngOnChanges from @Input in Angular

I have a @Input property in my child component of type Person and I'm passing the object from the parent component through an attribute Full working code is available in StackBlitz I explored the following question I got the point that what they…
3
votes
1 answer

ngOnChanges not working in Angular4

I know I am not the first to ask this question ,And I have tried the solutions of so many post in Stackoverflow regarding this but nothing is helped for me . I have an accordion menu in my parent component when the user clicked on those menus the …
Nikson
  • 900
  • 2
  • 21
  • 51
3
votes
2 answers

URL Change not firing in Angular

So my Angular app has a search bar, and if you enter something in this search bar, it does its search and comes to a results page. All good there. Now if your search doesn't return any results, the results page loads and tells you "searchterm" has…
Musical Coder
  • 449
  • 8
  • 14
3
votes
2 answers

Updating variable in Angular component when another variable has changed

I try something like this: component.ts displayName: string; email: string = `user+${this.displayName}@domain.com`; component.html
Maurice Wipf
  • 647
  • 2
  • 7
  • 13
3
votes
1 answer

deep checking for change similar to $watchCollection in Angular2

I'm using an array of objects which I'm passing from my parent component to child components. When a new item is pushed to the array or the property of one of the existing objects in the array changes it does not trigger the ngOnChanges for the…
1
2 3
8 9