Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AngularJS: Creating too many controllers, best practice? [closed]

Tags:

angularjs

I was wanting to get peoples feedback with regards to creating controllers. Before I just had a few controllers but recently I have broken these out into many more controllers so I get better separation and maintenance...

But I am unsure if this was a good idea!

How many controllers are classes as too many?

For example, before I had a page that show 1 table and an inner table. So I had 1 controller before and now I have added another controller so that 1 controller manages the outer table and the other the inner controller.

Also navigation and sub navigation, I am now using a number of controllers for this where as before I was using just one controller.

is this best practice?

Thanks in advance

like image 843
Martin Avatar asked Aug 01 '13 15:08

Martin


People also ask

Can we have multiple controllers in AngularJS?

An AngularJS application can contain one or more controllers as needed, in real application a good approach is to create a new controller for every significant view within the application.

What is not recommended in AngularJS?

It is tempting to do too much work in the AngularJS controller. After all, the controller is where the view first has access to JavaScript via $scope functions. However, doing this will cause you to miss out on code sharing across the site and is not recommended by AngularJS documentation.

What is $timeout in AngularJS?

The '$timeout' service of AngularJS is functionally similar to the 'window. setTimeout' object of vanilla JavaScript. This service allows the developer to set some time delay before the execution of the function.

What is $Watch in AngularJS?

$watch() function is used to watch the changes of variables in $scope object. Generally the $watch() function will create internally in Angularjs to handle variable changes in application.


1 Answers

I think this blog post by Vlad Orlenko is a good take on how to structure a big angular project: AngularJS Best Practices: I’ve Been Doing It Wrong! Part 1 of 3

Skip right to the "Layout of src: feature-based modularization"

like image 59
ravndal Avatar answered Sep 28 '22 00:09

ravndal