Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot access value from ngOnChanges SimpleChanges

Tags:

angular

I'm trying to access data from an input to a component, and using ngOnChanges to do so, but VS code complains that the input I'm trying to grab isn't a property of the SimpleChanges object, and thus doesn't compile. What am I doing wrong here?

@Input('filters') filtersInput;

ngOnChanges(changes: SimpleChanges) {
    console.log(changes);
    this.filters = changes.filtersInput.currentValue;
}

I get that filtersInput isn't a part of SimpleChanges, but as that's the class, it makes sense?

like image 976
Rohit Avatar asked Dec 05 '25 05:12

Rohit


1 Answers

It was just a compilation-time error because the interface of SimpleChanges doesn't have filtersInput property explicitly:

export interface SimpleChanges {
    [propName: string]: SimpleChange;
}

You will have to get the value by using indexer instead:

this.filters = changes["filtersInput"].currentValue;
like image 112
Harry Ninh Avatar answered Dec 07 '25 20:12

Harry Ninh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!