select - Angular2 - get selected part of text value -


i'd create simple editor make selected text bolder example.

there textarea "super text" value.

now select part of text (for example "super"). how selected value?

<textarea (selected)=".."></textarea> 

this call function every time select inside textarea.

<textarea (selected)="view(textarea.value)" #textarea></textarea> 

this print whole textarea value when select something. i'd print part of text, selected. how that?

i see binding function (selected) attribute on texarea. should (select) event fired selection. since getting callback executed, assume typo.

now main question. on textarea, have 2 properties selectionstart , selectionend, name suggest indexes of position in value selection starts , ends. can selected substring using

textarea.value.substring(textarea.selectionstart, textarea.selectend) 

you can pass value of expression inside component's functions. hence, this

<textarea (select)="view(textarea.selectionstart, textarea.selectend)" #textarea></textarea> 

here working fiddle same. https://jsfiddle.net/h191w4ed/1/


Comments

Popular posts from this blog

jOOQ update returning clause with Oracle -

java - Warning equals/hashCode on @Data annotation lombok with inheritance -

java - BasicPathUsageException: Cannot join to attribute of basic type -