gpt4 book ai didi

javascript - AngularJS应用程序的延迟加载

转载 作者:行者123 更新时间:2023-12-02 15:51:52 25 4
gpt4 key购买 nike

我需要的是引导 AngularJs 并按需渲染指令。想象一下,有一个启动页面不应该消耗资源(不需要时不应该下载太多,即使底部的 javascript 也会很糟糕)。

<!DOCTYPE html>
<body>
<button onclick="loadTheApp()">Launch app</button>
<script>
function loadTheApp() {
// load Angular and other files in this manner:
var el = document.createElement('script');
el.src = '/js/app.js';
document.body.appendChild(el);

// TODO: bootstrap Angular and render directive
}
</script>
</body>
</html>

最佳答案

我认为你可以使用这个解决方案:

el.onload = function() {
var element = document.body; // element which contains angular application

angular.bootstrap(element, ['myApp']);
}

假设 app.js 文件包含 Angular 和应用程序(构建版本),或者加载了 Angular 并且 app.js 文件包含应用程序 myApp

关于javascript - AngularJS应用程序的延迟加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31794078/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com