如何在angularjs多个JS文件分割单个控制器 [英] How to split single controller in multiple js files in angularjs

查看:1752
本文介绍了如何在angularjs多个JS文件分割单个控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我重写从银色光angularjs大型应用程序,而这样做,我意识到,我的每个控制器的JS文件是的跨越2000-3000线code 的的。我所有的code的严重依赖的范围的变量。不知道是否有任何机会,单控制器js文件分成多个JS文件?任何指针将是AP preciated。

I am rewriting a large application from silver-light to angularjs, while doing it, I am realizing that each of my controller js file is spanning 2000-3000 lines of code. All of my code is heavily dependent on scope variables. Wondering if there is any opportunity to split single controller js file into multiple js files? Any pointer would be appreciated.

推荐答案

使用多控制器来处理任务在你的页面。如果使用LARG控制器是不可避免的,你可以通过范围传递到另一个方法拆分定义多个文件,然后定义方法存在的其余部分。

Use multiple controller to handle the task in your page. If using a larg controller is unavoidable ,you can split the definition to multiple files by passing the scope to another method and then define the rest of methods there.

在第一个文件:

app.controller('CtrlA', function($scope){
app.expandControllerA($scope);

});

在第二个文件

app.expandControllerA = function($scope)
{

}

您可以传递任何变量或依赖关系expandControllerA功能。

You can pass any variable or dependencies to expandControllerA function.

这篇关于如何在angularjs多个JS文件分割单个控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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