簡體   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