I am currently working on a Chrome extension and my goal is to display the selected text on the tab within a textarea located inside the plugin.
Although I have successfully implemented the function to retrieve the selected text, I am facing challenges in setting the value of the textarea element within the plugin.
Inquiry: What is the proper method for storing the value so that it can be passed to the textarea using data-binding?
HTML:
<div>
<p>The selected text will be displayed here :</p>
<textarea name="selectedText" id="selectedText" [(ngModel)]="selectedText"></textarea>
<button (click)="getSelectedText()">Get the selected text</button>
</div>
TS:
export class CaptureComponent {
selectedText = '';
getSelectedText() {
chrome.tabs.executeScript( {
code: 'window.getSelection().toString();'
}, function(selection) {
this.selectedText = selection[0];
});
}
}
The selection[0]
is functioning properly, indicating that the issue lies in how I am attempting to store the data. However, I am struggling to identify the necessary modifications.