I'm developing an Angular 7 application which allows management of entities, for example Cars and Students.
The application components can be described by the following tree:
- Cars
- Cars/CreateCar (dialog)
- Students
- Students/CreateStudent (dialog)
While creating a Car in the CreateCar dialog, the user should be able to create and assign a new student as the owner of the Car using the CreateStudent dialog.
Similarly, while creating a Student in the CreateStudent dialog, the user should be able to create and assign a new car as a property of the Student using the CreateCar dialog.
When compiling, Angular displays: "WARNING in Circular dependency detected" and I understand that this should happen.
I've tried searching for patterns to solve this such as shared services but noone seems to work.
EDIT:
The relevant part of the constructor for both Dialogs:
constructor(
private readonly matDialog: MatDialog
) {
}
Inside CreateStudent dialog, method that opens the CreateCar dialog:
createCar(): void {
this.matDialog
.open(CreateCarDialogComponent)
.afterClosed().subscribe((car: Car) => {
// Do something with car
});
}
Inside CreateCar dialog, method that opens the CreateStudent dialog:
createStudent(): void {
this.matDialog
.open(CreateStudentDialogComponent)
.afterClosed().subscribe((student: Student) => {
// Do something with student
});
}
Any suggestions on solving this?
Thank you
EDIT 2:
Demo here https://stackblitz.com/edit/angular-bbfs8k
(Stackblitz doesn't seem to display the compile warning)
Cars
andStudents
are separate module? – Gastrotomy