本文介绍了如何将模块动态注入主 Angular 应用程序模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我没有在单页应用程序上使用 angular,但是由于加载顺序问题,我想定义一次主应用程序模块.同时,我想在每页的基础上注入/需要模块,而不是一概而论,因为并非所有 JS 文件都会在每个页面上加载.

I am not using angular on a single page application however I would like to define the main app module once due to load order issues. At the same time I would like to inject/require modules on a per page basis and not blanket as not all JS files will be loaded on every page.

我可以定义不需要模块的应用吗:

Can I define the app with no required modules:

app = angular.module("app", [])

app = angular.module("app", [])

是从控制器注入还是在稍后阶段注入?

and have them injected from a controller or at a later stage?

推荐答案

不,目前没有官方支持.在引导 AngularJS 应用程序之前,所有模块都必须在浏览器中加载(并声明为主应用程序模块的依赖项).

No, this is not officially supported at the moment. All the modules must be loaded in a browser (and declared as a dependency of a main application module) before AngularJS application is bootstrapped.

这篇关于如何将模块动态注入主 Angular 应用程序模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 12:43
查看更多