Angular 2 SimpleChanges Object throws error at first npm start
To make the compiler not complain just change your method definition for parameter one from SimpleChanges
to any
:
ngOnChanges(changes: any) {
//...
The accepted solution is suboptimal for TypeScript, as you're defeating the type system.
SimpleChanges
does not have an entry
property, so the compiler quite rightly balks. The solution is to treat the changes
object as an array:
ngOnChanges(changes : SimpleChanges){
if (changes['entry']) {
this.service.getComments(changes['entry'].currentValue.id)
}
}
Then you can continue to strongly type the ngOnChanges method.