[英]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 我基本上开始使用angular 4并使用ngChanges遇到此错误
Class 'GalleryComponent' incorrectly implements interface 'OnChanges'.Property 'ngOnChanges' is missing in type 'GalleryComponent'. 类'GalleryComponent'错误地实现了接口'OnChanges'。类型'GalleryComponent'中缺少属性'ngOnChanges'。
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 如果有人能提前注意到我所缺少的,我将非常感谢
First issue is function name: 第一个问题是函数名称:
OnChanges(){}
To
ngOnChanges(changes: SimpleChanges){}
You need to add parameter in ngOnChanges function changes: SimpleChanges
您需要在ngOnChanges函数changes: SimpleChanges
添加参数changes: SimpleChanges
ngOnChanges(changes: SimpleChanges) {
// changes.prop contains the old and the new value...
}
Please read this : https://angular.io/api/core/OnChanges 请阅读: https : //angular.io/api/core/OnChanges
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.