gpt4 book ai didi

angular - 类错误地实现了接口(interface) 'OnChanges' 。类型中缺少属性 'ngOnChanges'

转载 作者:行者123 更新时间:2023-12-03 20:32:05 25 4
gpt4 key购买 nike

我基本上开始使用 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com