Setting ng-model to a string containing </script> clogs angular?

74 Views Asked by At

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?

1

There are 1 best solutions below

3
On BEST ANSWER

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()?