Javascript里有如下的写法,可以用在定义方法时,或者定义方法时用在方法的参数上,非常灵活
// What does the following mean as a type: () => void = null
https://stackoverflow.com/questions/41868693/what-does-the-following-mean-as-a-type-void-null
- 定义方法时
export class ExcelOperationA {
constructor() {}
public exportExcelA: () => void;
}
import { createXlsx } from './create-xlsx';
import { ExcelOperationA } from './ExcelOperationA';
@Component({
selector: 'app-classNameB',
templateUrl: './ClassNameB.html'
})
export class ClassNameB {
constructor(
public excelOperationA: ExcelOperationA
) {
this.excelOperationA.exportExcelA= () => createXlsx(parameterA);
}
}
@Component({
selector: 'rms-pt',
templateUrl: `<app-classNameB [datas]="datas"></app-classNameB>`
})
export class RmsPtComponent {
public datas: Data[] = [];
constructor(private public excelOperationA: ExcelOperationA) {}
public excelDownloadHandle() {
this.excelOperationA.exportToExcel();
}
}