Passing Data with MatDialog to form
See original GitHub issuehi I want passing multi data with mat dialog to form please help me
import { Component, OnInit } from '@angular/core';
import { MatDialog } from '@angular/material';
import {DialogComponent } from '../../misc/dialog.component';
@Component({
selector: 'app-chart',
templateUrl: './chart.component.html',
styleUrls: ['./chart.component.css']
})
export class ChartComponent implements OnInit {
dialogResult = "";
firstname: string = ;
lastname: string;
gender: boolean = true;
constructor(public dialog: MatDialog) { }
ngOnInit() {
}
doChartSetting(){
let dialogRef = this.dialog.open(ChartDialogComponent, {
width:'600px',
data: { firstname: this.firstname, lastname:this.lastname,this.gender}
});
dialogRef.afterClosed().subscribe(result => {
this.firstname= result;
this.lastname= result;
this.gender= result;
});
}
}
My Dialog:
mport { Component, OnInit, Inject , ViewChild , Input , Output, EventEmitter , AfterViewInit} from '@angular/core';
import { MatDialogRef,MAT_DIALOG_DATA } from '@angular/material';
@Component({
selector: 'app-dialog',
templateUrl: './dialog.component.html',
styleUrls: ['./dialog.component.css']
})
export class DialogComponent implements OnInit {
constructor(public dialogRef: MatDialogRef<DialogComponent>,@Inject(MAT_DIALOG_DATA) public data:any) { }
ngOnInit() {
}
onClose(): void {
this.dialogRef.close();
}
}
dialog-component.html
<div class="dialog-wrapper">
<h3 mat-dialog-title >
Dialog
</h3>
<mat-dialog-content>
mat-form-field>
<input matInput placeholder="firstname" [(ngModel)]="data.firstname">
</mat-form-field>
<mat-form-field>
<input matInput placeholder="lastname" [(ngModel)]="data.lastname">
</mat-form-field>
<mat-checkbox [(ngModel)]="data.gender">gender</mat-checkbox>
</mat-dialog-content>
<hr>
<mat-dialog-actions>
<button mat-button color="primary" [mat-dialog-close]="data" cdkFocusInitial>ذخیره</button>
<button mat-button (click)="onClose()">close</button>
</mat-dialog-actions>
</div>
Issue Analytics
- State:
- Created 6 years ago
- Comments:6 (1 by maintainers)
Top Results From Across the Web
How to pass data to a MatDialog | nerd.vision
You can pass any kind of data to the component by adding data to the MatDialog's open() options. this.dialog.open(PersonalDetailsComponent, {
Read more >How to pass data to dialog of angular material 2 - Stack Overflow
1) add the import statement import { MatDialog} from '@angular/material'; · 2) add the property to the constructor params · 3) define the...
Read more >Angular Material 9|8|7 Add Dialog Modal and Pass Data ...
In the class file, import the MatDialog class from @angular/material package to provide the open() method. This method takes the component we ...
Read more >Angular Material Dialog: A Complete Example
Dialogs are often used to edit existing data. We can pass data to the dialog component by using the data property of the...
Read more >Dialog | Angular Material
The MatDialog service can be used to open modal dialogs with Material ... If you want to share data with your dialog, you...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Please keep GitHub issues for bug reports / feature requests. Better avenues for troubleshooting / questions are stack overflow, gitter, mailing list, etc.
You can always use like this:
and in your DialogComponent you can access it like: