Reputation: 1683
Helo All,
I am facing a issue, as I am new in Angular so it may be a something I am missing.
In my application, in one of the child component ngOnChanges is getting called irrespective on any change, In below screen shot you will find all the currentValues and previousvalues properties of changes object is same.
Let me know if I am missing something.
Please also refer below code
Thanks
import { Component, Input, SimpleChanges, OnInit} from '@angular/core'; import { OnChanges, OnDestroy } from @angular/core/src/metadata/lifecycle_hooks';
@Component({
selector: 'xxxxxx',
templateUrl: './result.component.html',
styleUrls: ['./result.component.css']
})
export class ResultComponent implements OnInit, OnChanges, OnDestroy {
@Input()
searchResults: SearchResults.SearchResult;
@Input()
searchText: string;
@Input()
loading: boolean = false;
ngOnInit() {
var logger = "stop me debugger";
}
ngOnChanges(changes: SimpleChanges) {
if (changes.searchResults && !changes.searchResults.firstChange) {
}
}
ngOnDestroy(): void {
var logger = "stop me debugger";
}
constructor() {
}
}
Upvotes: 1
Views: 1822
Reputation: 709
The lifecycle hook ngOnChanges
:
Respond when Angular (re)sets data-bound input properties. The method receives a
SimpleChanges
object of current and previous property values.
Called beforengOnInit()
and whenever one or more data-bound input properties change.
Because of this and some of your properties are inputs, ngOnChanges
gets called. That's also why the previousValue
and the currentValue
of the SimpleChanges
object are undefined
.
Upvotes: 0