I have a component which I'm trying to use from 2 places
- Normally, including the selector in some template for example
<comp-a></comp-a>
. - Inside of angular material dialog.
When using the same component with angular material dialog, I have to inject the below dependencies
constructor(
public dialogRef: MatDialogRef<CTConfigurationComponent>,
@Inject(MAT_DIALOG_DATA) public dialogData: any,
) {}
It is working fine with case 2, but case 1 is breaking with below error
Tried using @Optional()
, @Skip()
but no success.
Question -1 : 1. Is it possible to tell angular DI to skip few dependencies?
Tried public injector: @Injector
, and in constructor calling
this.dialogRef = this.injector.get(MatDialogRef<CTConfigurationComponent>);
is also not working.
EDIT-1:
(method) Injector.get(token: any, notFoundValue?: any)
Question - 2:
Is there any similar thing like notFoundValue
of Injector.get
when we are doing DI through constructor?
Any suggestion or explanation will be helpful
MatDialogRef
, does your html also contain<CTConfigurationComponent></CTConfigurationComponent>
?.const dialogRef = this.matDialog.open(CTConfigurationComponent, { minWidth: '320px', maxWidth: '450px', disableClose: true, panelClass: 'consent-banner-panel-class', backdropClass: 'backdrop-class-dark8', data: {} });
app.module.ts
code?@NgModule({ declarations: [CTOnboardingComponent, CTConfigurationComponent, VerifyDomainComponent], exports: [CTConfigurationComponent, VerifyDomainComponent], imports: [ CommonModule, FormsModule, ReactiveFormsModule, CTAngularImportsModule, CTOnboardingRoutingModule ], entryComponents: [CTConfigurationComponent, VerifyDomainComponent], providers: [CTOnboardingService] }) export class CTOnboardingModule {}