I have a service class in typescript, in the class i have declared a public array of strings, but when I trying push into the array it throws the undefined exception. What could I be doing wrong here?
Cannot read property 'audioInput' of undefined
The source code of the class is :
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);
}
}
}
}