Hello!
I have a circular dependency problem in an Angular project (4.3.X).
In the app/models
directory there are several files that represent the models received by the API.
Scenario:
// center.ts
import {User} from './user';
export class Center {
name: string;
users: User[];
constructor(data: any = {}) {
this.name = data.name;
this.users = (data.users || []).map(user => new User(user));
}
}
// user.ts
import {Center} from './center';
export class User {
name: string;
center: Center | null;
constructor(data: any = {}) {
this.name = data.name;
this.center = data.center ? new Center(data.center) : null;
}
}
Obviously, this produces a circular dependency.
How could I solve it?
Thanks!