I am trying to request permission from the user to record audio using AngularJs.
I have this method in my Component Class, but the class variables are not accessible using this
.
public recordAnswer(event: any) {
this.recording = true;
this.toastr.error('Something went wrong. Try again.'); // this line works
navigator.permissions.query({name: 'microphone'}).then(function (result) {
console.log(result);
if (result.state == 'granted') {
// start recording audio
} else if (result.state == 'prompt') {
} else if (result.state == 'denied') {
console.log(this.psp); // this line does not work
this.toastr.error('Something went wrong. Try again.'); // this line does not work
}
result.onchange = function () {};
});
}
I am getting this error:-
ERROR Error: Uncaught (in promise): TypeError: Cannot read properties of undefined (reading 'psp') TypeError: Cannot read properties of undefined (reading 'psp')
I had a look at this question, but I am not sure how I can access the class variables of MyComponent
.
How can I access class variables so I can display a toastr.error
to inform user to give permission?