简体   繁体   English

如何构造大型AngularJS应用程序

[英]How to structure large AngularJS applications

I have a web app that I'm building in AngularJS. 我有一个在AngularJS中构建的Web应用程序。 It has accumulated 500 lines of code and is quite a burden to sort through it all. 它已经积累了500行代码,要对所有代码进行分类是相当大的负担。 I was wondering if it would be possible for me to break off the logic into multiple files but still be able to interact with some of the $scope variables. 我想知道是否可以将逻辑拆分成多个文件,但仍然能够与某些$ scope变量进行交互。 Any resources on this topic would be appreciated. 对此主题的任何资源将不胜感激。

Ex: I have a bunch of logic dealing with tables generated by ng-repeat that doesn't need to interact with code from graphs that I'm generating using Canvas.JS 例如:我有很多逻辑处理由ng-repeat生成的表,不需要与我使用Canvas.JS生成的图形中的代码进行交互

Did you code all your app in a single controller? 您是否在单个控制器中编写了所有应用程序代码?

I would think about: 我会考虑:

  • Having an skinny controller (only exposing the scope content needed, and grabbing the content from services). 具有瘦控制器(仅公开所需的作用域内容,并从服务中获取内容)。

  • Implement services (Factories), in this factories you can for instance encapsulate your $http request to get the data you want to show. 实施服务(工厂),例如,在该工厂中,您可以封装$ http请求以获取要显示的数据。

  • Implement directives: eg if you are building a common chart, you can encapsulate it in a directive (it's like a control), is easier to maintain and reuse. 实施指令:例如,如果要构建通用图表,则可以将其封装在指令中(就像控件一样),更易于维护和重用。

Once you have that I would jump into Danilo great suggestions. 一旦有了,我就会向Danilo提出很好的建议。

Another link that might help you: 另一个可以帮助您的链接:

It's about a solution with RequireJS to partition the application in multiple modules that can be hooked together very easy. 这是一个使用RequireJS的解决方案,可将应用程序划分为多个模块,这些模块可以很容易地连接在一起。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM