我正在尝试从父组件打开模型。所以,我从父组件打开了虚拟对话框,从以下方面获得帮助:如何将数据传递给 Angular ng-bootstrap modal for binding。在 Dialog 而不是虚拟文本上,我有输入框来显示来自父组件的信息,同时用户可以编辑此信息并要求此更改发送回父信息。我尝试使用令牌注入来执行类似 Angular Material MAT_DIALOG 的操作,但我并没有完全遵循它。
import { Component, OnInit, InjectionToken, Injector, OnDestroy,
TemplateRef, Inject } from '@angular/core';
import {NgbActiveModal} from '@ng-bootstrap/ng-bootstrap';
export interface CancelDialogData {
name: string; // this can be any string;
Comments: string;
}
export declare const CUSTOM_DIALOG_DATA: InjectionToken<any>;
@Component({
selector: 'app-reject-dialog',
templateUrl: './reject-dialog.component.html',
styleUrls: ['./reject-dialog.component.css']
})
export class MyDialogComponent implements OnInit {
constructor(public activeModal: NgbActiveModal,
@Inject(CUSTOM_DIALOG_DATA) public data: CancelDialogData) { }
ngOnInit() {
}
onCancelClick(): void {
this.activeModal.close(); …Run Code Online (Sandbox Code Playgroud)