Reputation: 11812
I am trying to inject manually MAT_DIALOG_DATA dependency for Angular Material Dialog. I would like to reuse my component both inside dialog and as a regular component embedded in html. So I cannot use constructor injection as I need to conditionally inject this dependencies only If the component is inside dialog.
constructor(private injector : Injector,
private activatedRoute : ActivatedRoute,
private fb : FormBuilder,
private userService : UserService) {
this.resetToken = activatedRoute.snapshot.params['resetToken'];
if(this.hasResetToken()) {
this.dialogRef = this.injector.get(MatDialogRef);
this.data = this.injector.get(MAT_DIALOG_DATA);
}
The above MatDialogRef works correctly, but MAT_DIALOG_DATA InjectionToken doesn't work.
Upvotes: 0
Views: 773
Reputation: 11812
This injection works correctly. I have an error in hasResetToken() check related to undefined variable.
Upvotes: 0