Class incorrectly implements interface 'OnChanges'. Property 'ngOnChanges' is missing in type

Marcogomesr picture Marcogomesr · Jun 18, 2017 · Viewed 14k times · Source

I basically started using angular 4 and and working with the ngChanges I'm getting this error

Class 'GalleryComponent' incorrectly implements interface 'OnChanges'.Property 'ngOnChanges' is missing in type 'GalleryComponent'.

I don't really know what to do, I know that a class can have multiples interfaces but event using just one it shows the same error

import { Component, OnInit, OnChanges, Input } from '@angular/core';
import { ImageService } from '../image/shared/image.service';

@Component({
  selector: 'app-gallery',
  templateUrl: './gallery.component.html',
  styleUrls: ['./gallery.component.css']
})


export class GalleryComponent implements OnInit, OnChanges {
visibleImages: any[] = [];

 constructor(private imageService: ImageService) {
  this.visibleImages = this.imageService.getImages();
 }

 ngOnInit() {}

 OnChanges(){}

}

I'll be so thankful if anybody can notice what I'm missing thanks in advance

Answer

Vivek Doshi picture Vivek Doshi · Jun 18, 2017

First issue is function name:

OnChanges(){}
To
ngOnChanges(changes: SimpleChanges){}

You need to add parameter in ngOnChanges function changes: SimpleChanges

ngOnChanges(changes: SimpleChanges) {
    // changes.prop contains the old and the new value...
}

Please read this : https://angular.io/api/core/OnChanges