AngularJS:如何在ng-include中创建角加载脚本?
发布时间:2020-12-17 09:10:27 所属栏目:安全 来源:网络整理
导读:嘿,我正在建立一个有角度的网页。问题是有一些已经建立没有角,我必须包括他们 问题是这个。 我在main.html中有这样的东西: ngInclude src="partial.html"/ngInclude 和我的partial.html有这样的 h2 heading 1 h2script type="text/javascript" src="stati
嘿,我正在建立一个有角度的网页。问题是有一些已经建立没有角,我必须包括他们
问题是这个。 我在main.html中有这样的东西: <ngInclude src="partial.html"> </ngInclude> 和我的partial.html有这样的 <h2> heading 1 <h2> <script type="text/javascript" src="static/js/partial.js"> </script> 我的partial.js与angularjs无关。 nginclude工作,我可以看到html,但我看不到加载的javascript文件。我知道如何使用firebug / chrome-dev工具,但我甚至不能看到网络请求。我究竟做错了什么? 我knwo angular有一些特殊的含义脚本标签。我可以覆盖它吗?
接受的答案将不能从1.2.0-rc1(
Github issue)。
这里是一个由endorama创建的快速修复: /*global angular */ (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 code = elem.text(); var f = new Function(code); f(); } } }; }); }(angular)); 只需添加此文件,加载ngLoadScript模块作为应用程序依赖关系,并使用type =“text / javascript-lazy”作为脚本类型,您可以延迟加载partials: <script type="text/javascript-lazy"> console.log("It works!"); </script> (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |