I'm working on some app where there is an object that has some properties and when I make a http request new properties are added to that object.
this.user = {
id: 1,
name: 'John'
}
this.http.get('https://api.chucknorris.io/jokes/random')
.subscribe(joke => this.user.joke = joke);
The problem is that change detection isn't performed when making the request (this article states that it should be performed as long as I'm not modifying the change detection strategy).
Thus, ngOnChanges isn't called in the child component where I passed the user object and where I'm doing some complicated stuff when the value arrives from the server.
I attached a simplified stackblitz demo.
Note: I know that I can pass a copy of that object when the new data arrives, but I think it should be a better approach.
OnPush. If I misunderstood the article please let me know. Btw, I was also taking about the change detection strategy in my question, so I think this is another reason to do not mark the question as duplicateIf you modify the content of an object, Angular won't recognize.This is just a fact. If you were to use a primitive value, the change detection would pick up on that, but here we are dealing with an object and angular won't pick up the change unless the reference changes. Same would be, if this was an array and you would modify one object in the array, angular would not pick up on that.whenever some asynchronous operation has been performed, our application state might have changed. So there must be someone wrong (the guy that answered the stackoverflow question OR the guy that wrote the article). IMO, the guy that wrote the stackoverflow question is wrong, so I can't believe thatIf you modify the content of an object, Angular won't recognize. Please give me an official refecence.