收到错误
f.ngOnChanges不是函数
只有当我的tsconfig.json文件设置为目标es5时才会出现此问题。但是,如果我的目标是es6,则一切都按预期工作。
如果我的目标是es5,有谁知道如何让ngOnChange工作?
import {Component, ViewChild, Type, Input, Output, OnInit,OnChanges, ElementRef, EventEmitter, SimpleChanges} from '@angular/core';
@Component({
selector: "form",
styleUrls:['./crop.form.component.css'],
templateUrl: './crop.form.component.html',
})
export class CropFormComponent extends Type {
@Input() imageFile: any;
@Output() showUploadModal = new EventEmitter;
size: string;
// imageCropped: boolean; // imageNotCropped: boolean;
//Cropper 2 data
data:any;
constructor() { }
ngOnChanges(changes: SimpleChanges): void{
}
}
tsconfig.json
{
"compileOnSave": false,
"compilerOptions": {
"outDir": "./dist/out-tsc",
"sourceMap": true,
"declaration": false,
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"target": "es5",
"typeRoots": [
"node_modules/@types"
],
"lib": [
"es2017",
"dom"
]
}
}
答案 0 :(得分:2)
您需要实现OnChanges
接口才能使用该方法:
export class CropFormComponent extends Type implements OnChanges { ... }
在文档中有关于此的更多信息: