Make a web page with a folder of external files

后端 未结 4 1541
小蘑菇
小蘑菇 2021-02-19 16:13

Previously, I used $sce.trustAsHtml(aString) to inject a string (eg, ...) to a template

4条回答
  •  闹比i
    闹比i (楼主)
    2021-02-19 16:47

    I found a solution but might have gone a little too far. I created a script directive instead which will put the not-loaded script to the head of document. Something like this:

    app.directive('script', function() {
      return {
        restrict: 'E',
        scope: false,
        link: function(scope, elem, attr) {
          var scriptNode = document.createElement('script');
          scriptNode.src = attr.src;
          scriptNode.type = 'text/javascript';
          document.head.appendChild(scriptNode);
        }
      };
    });
    

    But, this obviously has few limitations including the src must be some absolute path. (Can overcome that but it would be dirtier..)

    I have put the sample HTML file somewhere I can tweak a little and use it to come up with this working plnkr

提交回复
热议问题