Class 错误地实现了接口 'OnChanges'。 属性 'ngOnChanges' 类型缺失
Class incorrectly implements interface 'OnChanges'. Property 'ngOnChanges' is missing in type
我基本上开始使用 angular 4 并在使用 ngChanges 时遇到此错误
Class 'GalleryComponent' incorrectly implements interface
'OnChanges'.Property 'ngOnChanges' is missing in type
'GalleryComponent'.
我真的不知道该怎么做,我知道一个 class 可以有多个接口,但事件只使用一个它显示相同的错误
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...
}
我基本上开始使用 angular 4 并在使用 ngChanges 时遇到此错误
Class 'GalleryComponent' incorrectly implements interface 'OnChanges'.Property 'ngOnChanges' is missing in type 'GalleryComponent'.
我真的不知道该怎么做,我知道一个 class 可以有多个接口,但事件只使用一个它显示相同的错误
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...
}