2017-06-18 79 views
0

我采用了棱角分明4基本启动,并与ngChanges工作,我得到这个错误类错误地实现了接口'OnChanges'。物业“ngOnChanges”中缺少类型

班“GalleryComponent”正确实现接口 “OnChanges'.Property‘ngOnChanges’在类型 'GalleryComponent'中缺失。

我真的不知道该怎么办,我知道,一个类可以有倍数接口,但使用的事件只是一个它显示了同样的错误

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(){} 

} 

我会,如果有人很感激可以看到什么我缺少 由于事先

+1

是不是函数定义:'ngOnChanges(变化:SimpleChanges)的''而不是onChanges()'? – puelo

+0

woooo你是对的..那是错误,非常感谢你 –

回答

2

第一个问题是函数名称:

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

相关问题