In AngularJS, any inline javascript code that included in HTML templates doesn't work

前端 未结 4 1983
孤城傲影
孤城傲影 2020-11-27 07:46

In AngularJS, any inline javascript code that included in HTML templates doesn\'t work.

For Example:

main.html file:

4条回答
  •  鱼传尺愫
    2020-11-27 07:59

    jQlite does not support script tags. jQuery does, so the recommendation is to include jQuery if you need this functionality.

    From Angular's Igor Minar in this discussion:

    we looked into supporting script tags in jqlite, but what needs to be done to get a cross-browser support involves a lot of black magic. For this reason we decided that for now we are just going to recommend that users use jquery along with angular in this particular case. It doesn't make sense for us to rewrite one third of jquery to get this working in jqlite.

    Here's the related github issue jqLite should create elements in same way as jQuery where Igor sums up, before closing the issue, with this:

    This is too much craziness for jqlite, so we are not going to do it. Instead we are going to document that if you want have script elements in ng:include or ng:view templates, you should use jquery.

    demo plunker with jquery

提交回复
热议问题