繁体   English   中英

类错误地实现了接口“ OnChanges”。 类型中缺少属性“ ngOnChanges”

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

我基本上开始使用angular 4并使用ngChanges遇到此错误

类'GalleryComponent'错误地实现了接口'OnChanges'。类型'GalleryComponent'中缺少属性'ngOnChanges'。

我真的不知道该怎么办,我知道一个类可以有多个接口,但是仅使用一个接口就可以显示相同的错误

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添加参数changes: SimpleChanges

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

请阅读: https//angular.io/api/core/OnChanges

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM