0

I was toying around with the plunker utilized by angular's own site at the document of ng-model:

http://plnkr.co/edit/?p=preview

If one sets the $scope.val to any string containing the '< /script>' bit in it the example seizes to work:

       $scope.val = 'problem </script> why?'

The only workaround I've found was to escape / ala:

       $scope.val = 'no problem like this <\/script> whats going on?'

This doesn't seem to be happening with any other tag, say 'span', 'div' and so on. Is this 'feature' documented somewhere?

XDS
  • 3,786
  • 2
  • 36
  • 56

1 Answers1

1

The problem here is simply the fact that </script> in the middle of your javascript code is interpreted by the browser as the closure of the script tag.

A common workaround in this case is to write it as '<' + '/script>' instead.

http://www.w3.org/TR/html4/interact/scripts.html

Similar question in stackoverflow:

Why split the <script> tag when writing it with document.write()?

Community
  • 1
  • 1
Matteo Tassinari
  • 18,121
  • 8
  • 60
  • 81
  • Good catch! Is there any other tag I need to be on the lookout for when writing code inside – XDS Jun 12 '15 at 15:05
  • I'm not really sure, sorry... I'd suggest you to give a look to javascript section of Mozilla MDN. – Matteo Tassinari Jun 12 '15 at 15:11
  • Thanks again. I found something indeed and will update the answer to make the link more visible to anyone that might stumble upon similar problems. – XDS Jun 12 '15 at 15:27