简体   繁体   English

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

[英]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.

相关问题 错误类“FirebaseApp”错误地实现了接口“App” - ERROR Class 'FirebaseApp' incorrectly implements interface 'App' 类“ ModalDirective”错误地实现了接口“ AfterViewInit” - class 'ModalDirective' incorrectly implements interface 'AfterViewInit' 类&#39;AuthGaurd&#39;错误地实现了接口CanActivate - Class 'AuthGaurd' incorrectly implements interface CanActivate 应为方法 ngOnChanges 实现 Angular 生命周期接口 OnChanges - Angular Lifecycle Interface OnChanges should be implemented for method ngOnChanges 在 ngOnChanges 钩子中检查 SimpleChanges 接口的类型 - Type checking for SimpleChanges interface in ngOnChanges hook Angular 生命周期错误 - 错误地实现了接口“DoCheck” - Angular lifecycle error - incorrectly implements interface 'DoCheck' 错误 TS2420:类 &#39;NgRedux<RootState> &#39; 错误地实现了接口 &#39;ObservableStore<RootState> &#39; - error TS2420: Class 'NgRedux<RootState>' incorrectly implements interface 'ObservableStore<RootState>' 您可以在实现另一个接口的组件的接口中键入字段吗? - Can you type a field in an interface to a Component that implements another interface? 在组件模型属性上触发ngOnChanges - fire ngOnChanges on component model property 通过更改数据绑定对象的属性来触发OnChanges - Trigger OnChanges by changing a property on the data bound object
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM