When press on word get this word from <p>

#1

hi , i have app that show a text i want when the user press or touch one of these word get it back to the system
ex:

hi i'm sofe i'm new to ionic, and i love it so much

i want when i touch or press for example on "new" i want this word save on variable
#2

bro you can try to take codes from stacks overflow you get more …new experience …

Thanks
Trivanks

#3

i didn’t find the concept that i want

#4

can you please explain briefly your requirement brother… what you actually…

#5

try this:
script code=>

var text = "This is my text"; // your text you want to display

var text_arr = text.split(" ");// convert to array

getClicked(text_clicked){
alert(text_clicked); // or do something else with the text
}

html code => display your text with on-click event, something like below

       <p><span *ngFor = "let myText as text_arr ; let i = index" (click)="getClicked({{ myText[i] }})"> {{ myText[i] }}</span></p>

I just created those chunks of code impromtu and haven’t checked it. Hope it helps.

#6

i will try it now , thank u so much

#7

i tried it, it works thank u so much, but it split the first word not all the graph

#8

i figuerd what it the proplem
it should be like that:

  <p><span *ngFor = "let myText of text_arr ; let i = index" (click)="getClicked( myText )"> 
              {{ myText }}
            </span>
          </p>

thank u so much mister Cabz
u helped me sooooooo much
thanks

#9

No problem. Glad to help.

1 Like