Skip to content

Instantly share code, notes, and snippets.

@haifahrul
Last active February 7, 2019 04:47
Show Gist options
  • Save haifahrul/ad52bf762c37722530b6174c216d7593 to your computer and use it in GitHub Desktop.
Save haifahrul/ad52bf762c37722530b6174c216d7593 to your computer and use it in GitHub Desktop.
Modal Angular 6
# Modal In Angular 6
## Component.ts
// Modal
private id: number;
public action: string;
public title: string;
public modalTitle: string;
public modalReference: NgbModalRef;
public isProcessing = false;
public formData: Array<object>;
// End Modal
public submitHandler = () => {
const data: object = {};
const { id, action } = this;
this.formData.map((item: any) => {
if (item.tag === 'timeRange') {
data[item.name1] = item.model1;
data[item.name2] = item.model2;
} else {
data[item.name] = item.model;
}
});
this.isProcessing = true;
if (action === 'edit') {
// this.update(id, data); // Service to update
} else if (action === 'create') {
// this.create(data); // Service to create
}
}
## Component.html
<ng-template #modalContent let-c="close" let-d="dismiss">
<app-modal-form-2
[modalTitle]="modalTitle"
[closeModalHandler]="c"
[dismissModalHandler]="d"
[submitHandler]="submitHandler"
[isProcessing]="isProcessing"
[formData]="formData"
>
</app-modal-form-2>
</ng-template>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment