angular.js icon indicating copy to clipboard operation
angular.js copied to clipboard

Support `<script>` tag inside `<script type="text/ng-template">`

Open JensRantil opened this issue 13 years ago • 6 comments

I haven't seen an issue for this. Either 1) there's is support for this, but not documented or 2) there's currently no support for this.

The issue:

<script type="text/ng-template" id="/tpl.html">
    <script>
        ...some other script...
    </script>
</script>

cannot be written because the first </script> closes the first <script ...>. This leads to the fact that http://docs.angularjs.org/partials/api/ng.directive:script.html gets generated incorrectly and is thus not presented correctly in http://docs.angularjs.org/api/ng.directive:script (see this comment).

JensRantil avatar May 29 '13 15:05 JensRantil

The question is, would simply escaping the opening braket solve the documentation issue? That is:

<script type="text/ng-template" id="/tpl.html">
    <script>
        ...some other script...
    &nbsp;/script>
</script>

JensRantil avatar May 29 '13 15:05 JensRantil

Include jquery and script tags will work in templates

jasonals avatar May 30 '13 01:05 jasonals

Include jquery and script tags will work in templates

But isn't that simply the result of the webbrowser automatically closing the opened tag because it doesn't have a close tag itself?

A StackOverflow with a similar issue: http://stackoverflow.com/questions/14261232/including-script-tag-in-script-type-text-template-tag

JensRantil avatar May 30 '13 08:05 JensRantil

OK, so we've got this in the build-generated docs (build/docs/partials/api/ng.directive:script.html):

<script type="text/ng-template" id="index.html-193">
  <script type="text/ng-template" id="/tpl.html">
    Content of the template.
  </script>

  <a ng-click="currentTpl='/tpl.html'" id="tpl-link">Load inlined template</a>
  <div id="tpl-content" ng-include src="currentTpl"></div>
</script>

Should probably escape <script> while generating docs.

pkozlowski-opensource avatar Jun 02 '13 13:06 pkozlowski-opensource

I don't believe that we can support script elements within script elements without resorting to some special angular-specific escaping/unescaping (something I'm not interested in).

in scenarios where script elements are needed in templates (not that common), the templateCache should be populated directly via imperative code. that's what we should do for our docs app as well.

@petebacondarwin is rewriting the docs generator, so there is actually a good chance of this happening reasonably soon.

in the long term, we'll move over to using template elements which don't suffer from this limitation.

I'm going to close this issue, because as I said, we can't fix this without angular-specific hacks.

IgorMinar avatar Jan 08 '14 09:01 IgorMinar

Aight. Thanks for having a look at this issue!

JensRantil avatar Jan 11 '14 12:01 JensRantil