2

Surprised that I cannot find such simple need in 15 minutes.

I am forming string based on user input and it might have some special characters, like < or /. To be safe I want to add html encoding to such line of code (typescript):

const suggest: any = { id: '', title: `Suggest ${q} ${type}`, type: type, query: q };

title later used as typeaheadOptionField and I do not see an easy way to use innerHTML.

Thanks!

st78
  • 8,028
  • 11
  • 49
  • 68
  • TypeScript is a superset of JavaScript, meaning any valid JS is valid TS. Is there a reason that using the HTML encoding provided in other JS answers on StackOverflow isn't working for you? – Daniel W Strimpel Apr 11 '18 at 02:25
  • @DanielWStrimpel typical JS advice I found is to use JQuery, e.g. $('
    ').text(unsafestring).html()
    – st78 Apr 11 '18 at 04:43
  • 1
    There are non-jQuery examples on SO posts: https://stackoverflow.com/a/7124052 – Daniel W Strimpel Apr 11 '18 at 04:49

0 Answers0