Methods
|
onJsonValueCancel
|
onJsonValueCancel()
|
|
|
Cancel the changes and reset the JSON value.
|
|
onJsonValueSave
|
onJsonValueSave()
|
|
|
Save the JSON value and emit the updated value.
|
|
data
|
Type : unknown
|
Default value : inject(MAT_DIALOG_DATA)
|
|
|
import {
Component,
CUSTOM_ELEMENTS_SCHEMA,
inject,
ChangeDetectionStrategy,
} from "@angular/core";
import { FormControl, ReactiveFormsModule } from "@angular/forms";
import { MatButtonModule } from "@angular/material/button";
import {
MAT_DIALOG_DATA,
MatDialogModule,
MatDialogRef,
} from "@angular/material/dialog";
import { DialogCloseComponent } from "app/core/common-components/dialog-close/dialog-close.component";
import { JsonEditorComponent } from "../json-editor.component";
@Component({
changeDetection: ChangeDetectionStrategy.OnPush,
selector: "app-json-editor-dialog",
standalone: true,
imports: [
JsonEditorComponent,
MatDialogModule,
DialogCloseComponent,
MatButtonModule,
ReactiveFormsModule,
],
schemas: [CUSTOM_ELEMENTS_SCHEMA],
templateUrl: "./json-editor-dialog.component.html",
styleUrl: "./json-editor-dialog.component.scss",
})
export class JsonEditorDialogComponent {
data = inject(MAT_DIALOG_DATA);
private dialogRef =
inject<MatDialogRef<JsonEditorDialogComponent>>(MatDialogRef);
jsonDataControl: FormControl;
constructor() {
const data = this.data;
this.jsonDataControl = new FormControl(data?.value || {});
}
/**
* Save the JSON value and emit the updated value.
*/
onJsonValueSave() {
if (this.jsonDataControl.valid) {
this.dialogRef.close(this.jsonDataControl.value);
}
}
/**
* Cancel the changes and reset the JSON value.
*/
onJsonValueCancel() {
this.dialogRef.close(null);
}
}
<mat-dialog-content class="mat-typography">
@if (data.closeButton) {
<app-dialog-close mat-dialog-close></app-dialog-close>
}
<div class="json-editor">
<app-json-editor
[formControl]="jsonDataControl"
class="json-editor-dialog"
></app-json-editor>
<div class="flex-row json-editor-actions">
<button
[disabled]="jsonDataControl.invalid"
mat-raised-button
(click)="onJsonValueSave()"
i18n
>
Save
</button>
<button mat-raised-button (click)="onJsonValueCancel()" i18n>
Cancel
</button>
</div>
</div>
</mat-dialog-content>
@use "variables/sizes";
.mat-typography {
max-height: 90vh;
margin-top: sizes.$large;
width: 60vw;
}
.json-editor-actions {
justify-content: end;
margin-top: sizes.$regular;
gap: sizes.$regular;
}
.json-editor-dialog {
height: 50vh;
}
Legend
Html element with directive