How to get the selected word from paragraph? ionic-v2

i am beginner in coding in ionic v2 i need help where my project is: i display a paragraph and the user should select word, when user select word the system take it and compare it with something please i need help

Hi !
This might sound obvious but that’s not an ionic issue. That sounds like you need to catch up on angular.
Either you find a library or create a directive that takes the content on the element and attache a (click) event listener to every element in the parragraph.

So ‘ionic g directive makeTouchable’ is a good place to start. But hat has its own set of challenges. Like digging in angular docs. I did it a few days ago . Took me about an hour.

Something much more dirty would be

Content ="an entire parragraph ....";

Content.split(' ').map( word =>{ return   <span (click)="console.log(word)">{{ word }}</span>).join();


But then you would need to parse the HTML I’ve Never done that. Also I’m pretty sure that’s jsx.sorry I just finished 12 hours of react debugging. I don’t remember how to do that in angular.

Still, the easiest option is to pull down a library from npmjs
All This should get you started or at least give some else an idea to point you In the right direction .

1 Like

first thank you very much for replaying to me.
i didn’t understand your point very much. if i take the code that you put her in html file is it going to work???
this is the first time i use ionic framework …

Hi. Did you ever figure it out?

I’ve just realized you can do a split(’ ') on the parragraph and just spit each word as a span with a click event. Listener. Nice and dirty.
I might be able to lend you a hand.