Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 381
Marcogomesr Avatar asked Mar 09 '23 19:03

Marcogomesr


1 Answers

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

like image 152
Vivek Doshi Avatar answered Mar 11 '23 11:03

Vivek Doshi