angular.js - angularjs的include指令,include的页面无法加载js
phpcn_u1582
phpcn_u1582 2017-05-15 16:50:36
0
1
546
<p ng-include="'project_index.jsp'">

project_index.jsp中:

<script type="text/javascript" ng-src='{{generateURL("/scripts/tab.js")}}'></script>

生成的url是正确的,在浏览器中可以访问,但是我看过请求的记录,这个js没有被加载。所以js中的内容也无法执行。请问我的做法的问题在哪儿?感谢回答~

phpcn_u1582
phpcn_u1582

reply all(1)
黄舟

Found on stack. Personal test is useful.

(function (ng) {
'use strict';
var app = ng.module('ngLoadScript', []);
app.directive('script', function() {
return {
  restrict: 'E',
  scope: false,
  link: function(scope, elem, attr) 
  {
    if (attr.type==='text/javascript-lazy') 
    {
      var s = document.createElement("script");
      s.type = "text/javascript";                
      var src = elem.attr('src');
      if(src!==undefined)
      {
          s.src = src;
      }
      else
      {
          var code = elem.text();
          s.text = code;
      }
      document.head.appendChild(s);
      elem.remove();
    }
  }
};
});
}(angular));

Write the above code into a js file, then inject this module ngLoadScript into your current application, and then use type="text/javascript-lazy" in the <script> tag.
This angular module have been created by @subudeepak(https://github.com/subudeepak) based on the code posted by @endorama (https://github.com/endorama)
* (based upon the code
* posted by @olostan (https://github.com/olostan) )

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template