I've been working on incorporating more classes into my project, and I recently created an interface and class for a model:
export interface IIndexClient {
id?: number;
name?: string;
user_id?: number;
location_id?: number;
mindbody_id?: number;
appointment_type?: string;
found?: boolean;
time?: string;
status?: string;
submitted?: boolean;
consult_status?: boolean;
consultation_id?: number;
consultation?: IConsultation;
}
export class IndexClient implements IIndexClient {
public id?: number;
public name?: string;
public user_id?: number;
public location_id?: number;
public mindbody_id?: number;
public appointment_type?: string;
public found?: boolean;
public time?: string;
public status?: string;
public submitted?: boolean;
public consult_status?: boolean;
public consultation_id?: number;
public consultation?: IConsultation;
constructor( data: Partial<IIndexClient>,
private locationService ) {
Object.assign(this, data);
}
getLocationName() : string {
return this.locationService.locations.filter((loc) => loc.id == this.location_id)[0].name
}
I want to use the getLocationName()
function in my code, but it requires an instance of LocationService
to access the locations
. The problem is that every time I create an instance of IndexClient
, I have to provide the LocationService
:
this.client = new IndexClient(this.client, this.locationService);
Is there a way to access a provider's value inside my IndexClient
class without having to provide it each time?