从1.2.0-rc1
+(Github问题)开始,可接受的答案将不起作用。
这是由endorama创建的快速修复:
(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 pre = elem.text(); var f = new Function(pre); f(); } } }; });}(angular));只需添加此文件,将
ngLoadscript模块作为应用程序依赖项加载,并
type="text/javascript-lazy"作为脚本的类型即可将其延迟加载到局部中:
<script type="text/javascript-lazy"> console.log("It works!");</script>


