What does the following mean as a nameTest2: () => void = null and nameTest3: () => void
阿新 • • 發佈:2018-12-24
Javascript裡有如下的寫法,可以用在定義方法時,或者定義方法時用在方法的引數上,非常靈活
- 定義方法時
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();
}
}