我基本上开始使用 angular 4 并使用 ngChanges 我收到了这个错误
Class 'GalleryComponent' incorrectly implements interface 'OnChanges'.Property 'ngOnChanges' is missing in type 'GalleryComponent'.
我真的不知道该怎么做,我知道一个类可以有多个接口(interface)但事件只使用一个它显示相同的错误
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(){}
}
如果有人能注意到我错过了什么,我将不胜感激
提前致谢
最佳答案
第一个问题是函数名称:
OnChanges(){}
To
ngOnChanges(changes: SimpleChanges){}
您需要在 ngOnChanges 函数中添加参数
changes: SimpleChanges
ngOnChanges(changes: SimpleChanges) {
// changes.prop contains the old and the new value...
}
请阅读这个 :
https://angular.io/api/core/OnChanges
关于angular - 类错误地实现了接口(interface) 'OnChanges' 。类型中缺少属性 'ngOnChanges',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44614572/