I have a dialog component and app component where the material dialog is implemented. Here is the code of app component
import { Component } from '@angular/core';
import {VERSION, MatDialog, MatDialogRef} from '@angular/material';
import { DialogComponent } from '../dialog.component';
@Component({
selector: 'my-app',
templateUrl: './app.component.html',
styleUrls: [ './app.component.css' ]
})
export class AppComponent {
name = 'Angular 5';
DialogRef: MatDialogRef<DialogComponent>;
constructor(private dialog: MatDialog) {}
ngOnInit() {
}
addItem() {
this.DialogRef = this.dialog.open(DialogComponent);
}
receiveMessageFromDialogComponent() {
// how to receive message from dialog component
}
closeDialog(): void {
this.DialogRef.close();
}
}
The dialog component is where the form is implemented, I need to take the form value and receive it in here. I tried using angular input and output to achieve this but dint work coz there is no child and parent communication. Here is the Dialog component
import { Component } from '@angular/core';
@Component({
template: `
<h1 mat-dialog-title>Add Item</h1>
<mat-dialog-content>
<mat-form-field class="example-full-width">
<input matInput placeholder="Item name here...">
</mat-form-field>
</mat-dialog-content>
<mat-dialog-actions>
<button mat-button (click)="saveMessage()">Add</button>
<button mat-button (click)="closeDialog()">Cancel</button>
</mat-dialog-actions>
`
})
export class DialogComponent {
saveMessage() {
console.log('how to send data to the app component');
}
closeDialog() {
console.log('how to close');
}
}