Я не знаю, что это правильный способ решения проблемы, но я стараюсь помочь, если это работает для вас
network.component.html
<button mat-raised-button (click)="openDialog()">Click</button>
network.component.ts
constructor(private fb: FormBuilder, private _AS: AuthService, public dialog: MatDialog) {}
openDialog(): void {
const dialogRef = this.dialog.open(DialogOverviewExampleDialog, {
width: '250px',
data: ''
});
dialogRef.afterClosed().subscribe(result => {
this._AS.emitTransaction(result);
console.log('The dialog was closed');
});
}
диалоговое окно TS:
@Component({
selector: 'app-dialog',
templateUrl: 'dialog.html',
})
export class DialogOverviewExampleDialog {
form: FormGroup;
constructor(
public dialogRef: MatDialogRef<DialogOverviewExampleDialog>,
@Inject(MAT_DIALOG_DATA) public data: any, private fb: FormBuilder) {
this.form = this.fb.group({
sender: ['', Validators.required],
recipient: ['', Validators.required],
amount: ['', Validators.required],
fee: ['', Validators.required],
releasedAt: [moment(), Validators.required]
});
}
onNoClick(): void {
this.dialogRef.close();
}
}
dialog.html
<div [formGroup]="form">
<mat-form-field class="example-full-width">
<input matInput placeholder="first" formControlName="sender">
</mat-form-field>
<mat-form-field class="example-full-width">
<input matInput placeholder="second" formControlName="recipient">
</mat-form-field>
<mat-form-field class="example-full-width">
<input matInput placeholder="second" formControlName="amount">
</mat-form-field>
<mat-form-field class="example-full-width">
<input matInput placeholder="second" formControlName="fee">
</mat-form-field>
<mat-form-field class="example-full-width">
<input matInput placeholder="second" formControlName="releasedAt">
</mat-form-field>
<button [mat-dialog-close]="form.value">save</button>
</div>
AuthService:
export class AuthService {
public transaction = new BehaviorSubject<any>(false);
transaction$ = this.transaction.asObservable();
emitTransaction(data: any) {
this.transaction.next(data);
}
транзакция-pool.component.ts
ngOnInit() {
this._AS.transaction$.subscribe(data => {
this.data = data;
console.log(this.data);
});
}