Skip to content

Instantly share code, notes, and snippets.

@Ze1598
Created December 28, 2019 19:02
Show Gist options
  • Save Ze1598/37fc4e1dff8b99f2f25829e8db760f38 to your computer and use it in GitHub Desktop.
Save Ze1598/37fc4e1dff8b99f2f25829e8db760f38 to your computer and use it in GitHub Desktop.
Reusable modal component: modal.component.ts (final version)
import { Component, OnInit, Inject } from '@angular/core';
import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog';
import { ModalActionsService } from 'src/app/services/modal-actions.service';
@Component({
selector: 'app-modal',
templateUrl: './modal.component.html',
styleUrls: ['./modal.component.css']
})
export class ModalComponent implements OnInit {
constructor(
public dialogRef: MatDialogRef<ModalComponent>,
@Inject(MAT_DIALOG_DATA) private modalData: any,
private modalService: ModalActionsService
) {}
ngOnInit() { }
actionFunction() {
this.modalService.modalAction(this.modalData);
this.closeModal();
}
closeModal() {
this.dialogRef.close();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment