如何在定义模块时注入 AngularJS 模块依赖项而不在依赖项数组中声明它? [英] How can I inject an AngularJS module dependency without declaring it in the dependency array when the module is defined?

查看:27
本文介绍了如何在定义模块时注入 AngularJS 模块依赖项而不在依赖项数组中声明它?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前我知道的使模块依赖项可用的唯一方法是在声明模块时指定它们.例如:

Currently the only way that I know of to make module dependencies available is to specify them when a module is declared. e.g.:

angular.module("myApp",["myDependentModule"]);

当应用程序变大并且模块有很多依赖项、必须加载的库时,这就会成为一个问题.如果用户访问的第一页的任何模块都不需要这些库,那么似乎可以推迟这些依赖项以缩短加载时间.

This becomes a problem when the app gets large and modules have a lot of dependencies, libraries that must be loaded. If these libraries aren't required for any of the modules that the first page the user visits, it seems that those dependencies could be deferred to improve load time.

任何建议将不胜感激.

推荐答案

使用 angular.injector(...)https://docs.angularjs.org/api/ng/function/angular.注射器

Use angular.injector(...) https://docs.angularjs.org/api/ng/function/angular.injector

在此处提及和示例:

 var injector = angular.injector(['someModule']);
 var someService = injector.get('someService');

AngularJS - 将工厂从另一个模块注入提供者

这篇关于如何在定义模块时注入 AngularJS 模块依赖项而不在依赖项数组中声明它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆