How do I highlight the text in the web and use that somewhere else?

What i want to do in ionic, is that simply a user selects some text and then clicks on a button/popup and this selected text appears in the console.
There is something i found in javascript but looks like it dosent work in ionic

Here is a similar demo
How do I get there
All the efforts are appreciated