angular-自定义MatDialogConfig文件的输入

时间:2018-10-11 08:12:59

标签: javascript angular typescript

因此,我为所有我的 material dialogs 有一个自定义的 MaterialDialogConfig 文件,如下所示:

import { MatDialogConfig } from "@angular/material";

export class MaterialDialogConfig extends MatDialogConfig {
    constructor(data: any = {}, width: string = "720px") {
        super();
        this.data = data;
        this.width = width;
        this.hasBackdrop = true;
        this.disableClose = true;
        this.closeOnNavigation = true;
    }
}

我的对话框组件如下所示:

constructor(
    private service: AppService,
    public dialogRef: MatDialogRef<DIALOGCOMPONENT>,
    @Inject(MAT_DIALOG_DATA) public data: any
) {}

ngOnInit() {}

如何将 width 属性作为所有单独对话框组件实例的输入?

1 个答案:

答案 0 :(得分:0)

原来是一个快速修复。只需将变量导出为常量即可:

import { MatDialogConfig } from "@angular/material";

export class MaterialDialogConfig extends MatDialogConfig {
    constructor(data: any = {}, width: string = "720px") {
        super();
        this.data = data;
        this.width = width;
        this.hasBackdrop = true;
        this.disableClose = true;
        this.closeOnNavigation = true;
    }
}

export const DIALOG_SMALL: string = "480px";
export const DIALOG_MID: string = "720px";
export const DIALOG_BIG: string = "1200px";