I am writing a service but am encountering a problem.
The service contains a variable that is implementing an interface. When the service is first created the variable holds the value of undefined.
To explain it with less code I came up with the following example.
This is an interface.
interface objectWithSensors {
sensor1: number[];
sensor2: number[];
}
The service has a varaible of this type declared as:
private sensorObject: objectWithSensors;
At this point in time this object is undefined.
Is there a way to define it at this point (put an object in there that I can later modify) or should I change the interface to a class with public attributes?
sensorObjectwith a value. You need to define a class that implements this interface. You then instantiate an object of this class, for example in your service's constrictor, or you use dependency injection to assign it.