I am trying to open model from parent component. So, I got the dummy dialog opened from parent component taking help from : how to pass data to Angular ng-bootstrap modal for binding. On Dialog instead of dummy text , I have input box to display the infomration from parent component and at the same time user can edit this information and require this change to send back to Parent information. I try to do something like Angular Material MAT_DIALOG has using tokeninjection but I am not fully following it.
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();
}
}
From parent Component:
const dialogRef = this.modal.open(CancelDialogComponent, data:
{name: '', approverComments: ''});
when I am trying to pass this data , i have compiler error that data is not a NgbModalOptions. I really don't understand the InjectionToken here, it just appear more cleaner than @Input/ @output. Please assist how to achieve it like Active material Dialog.