0

收到错误

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"
    ]
  }
}
4

1 回答 1

1

您需要实现OnChanges接口才能使用该方法:

export class CropFormComponent extends Type implements OnChanges { ... }

更多关于这个的文档:

https://angular.io/api/core/OnChanges

https://angular.io/guide/lifecycle-hooks#onchanges

于 2017-10-27T11:27:07.670 回答