I'm encountering an issue with my TypeScript service class. I've declared a public array of strings within the class, but when I attempt to push values into the array, an undefined exception is thrown. Can someone help me identify what I might be doing wrong?
Cannot read property 'audioInput' of undefined
Here's the code snippet for the class:
export class AudioService {
public audioInput:Array<String>=[];
_navigator=<any> navigator;
constructor(){
}
getDevices(){
this._navigator.mediaDevices.enumerateDevices().then(this.gotDevices)
}
gotDevices(deviceInfos) : any {
for (let i = 0; i !== deviceInfos.length; ++i) {
const deviceInfo = deviceInfos[i];
let value = deviceInfo.deviceId;
if (deviceInfo.kind === 'audioinput') {
this.audioInput.push(deviceInfo.label);
}
}
}
}