如何在 AngularJS 中减轻模块化? [英] How is modularity mitigated in AngularJS?

查看:27
本文介绍了如何在 AngularJS 中减轻模块化?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在使用 AngularJS 的种子应用程序,我注意到应用程序的大多数依赖项(控制器、指令、过滤器、服务)都是预先加载的.我想知道如何将 Angular 应用程序模块化为更小的字节,除非需要,否则不会加载依赖项.

I've been playing with the seed app for AngularJS and I noticed that most dependencies (controllers, directive, filters, services) for the app are loaded up front. I was wondering how to modularize an Angular app into smaller bytes, where dependencies aren't loaded unless required.

例如,如果我有一个包含购物车、添加/编辑送货地址、搜索结果、产品详细信息、产品列表等的大型应用程序......购物网站上的用户可能永远不会遇到任何这些视图,但看起来(来自种子应用程序)这些所有视图的代码都是在启动时加载的.

For example, if I had a large application that had a cart, add/edit shipping address, search results, product details, product lists, etc... A user on a shopping site may never encounter any of these views, but it looks like (from the seed app) that the code for these all views are loaded in at startup.

如何在 AngularJS 中减轻模块化?

How is modularity mitigated in AngularJS?

推荐答案

我最近一直在玩 require 模块和 angular,我实现了部分和控制器的延迟加载.

I've been playing lately with require modules and angular and I've implemented lazy loading of partials and controllers.

无需对 Angular 源(1.0.2 版)进行任何修改即可轻松完成.

It can be easily done without any modifications to Angular sources (version 1.0.2).

存储库:https://github.com/matys84pl/angularjs-requirejs-lazy-控制器 .

还有一个使用 yepnope 的实现(https://github.com/cmelion/angular-yepnope) 由 Charles Fulnecky 制作.

There is also an implementation that uses yepnope (https://github.com/cmelion/angular-yepnope) made by Charles Fulnecky.

这篇关于如何在 AngularJS 中减轻模块化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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