2017-06-18 60 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

相關問題