Having looked at a few tutorials on how to get the selected text in an Angular project, the following snippet is always used, but when I include it in my component, I get errors:
getSelection() {
let text = "";
if (window.getSelection) {
text = window.getSelection().toString();
} else if (document.selection && document.selection.type != "Control") {
text = document.selection.createRange().text;
}
return text;
}
The first red underline error is Object is possibly 'null'.
The other three are Property 'selection' does not exist on type 'Document'.
What am I missing here?
