4

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

Claies
  • 22,124
  • 4
  • 53
  • 77
Marcogomesr
  • 2,614
  • 3
  • 30
  • 41

1 Answers1

7

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

Vivek Doshi
  • 56,649
  • 12
  • 110
  • 122