将长控制器划分为Angular Js中的小型控制器

时间:2020-12-12 12:08:32

I am working on complex application and every controller has more than 2000 lines. Can anyone suggest to break the codes into small controllers and used as a dependency on main controller.

我正在研究复杂的应用程序,每个控制器都有超过2000行。任何人都可以建议将代码分解为小型控制器并用作主控制器的依赖。

1 个解决方案

#1


0  

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

使用多个控制器来处理页面中的任务。如果使用长控制器,可以通过将范围传递给另一个方法将定义拆分为多个文件,然后在那里定义其余方法。

In the first file:

在第一个文件中:

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

});

In the second file

在第二个文件中

app.expandControllerA = function($scope)
{

}

You can pass any variable or dependencies to expandControllerA function.

您可以将任何变量或依赖项传递给expandControllerA函数。

#1


0  

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

使用多个控制器来处理页面中的任务。如果使用长控制器,可以通过将范围传递给另一个方法将定义拆分为多个文件,然后在那里定义其余方法。

In the first file:

在第一个文件中:

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

});

In the second file

在第二个文件中

app.expandControllerA = function($scope)
{

}

You can pass any variable or dependencies to expandControllerA function.

您可以将任何变量或依赖项传递给expandControllerA函数。