Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the benefit, if any, of using angular.module for creating controllers?

I am new to angular.js and currently writing my first project.

Currently my controllers look like this, for example:

function MyCtrl($scope, MyService) {
    $scope.foo = MyService.doStuff();
}

They work just fine that way (so far), but I browsed the source of another AngularJS application and noticed they're using angular.module to create their controllers.

Why, if at all, would I want to do this in my own application?

like image 320
Trae Avatar asked Jul 09 '12 03:07

Trae


Video Answer


1 Answers

If you have multiple angular applications on your page and they have controllers with the same name you'll need to use module.controller to avoid conflicts. The same if you want to avoid pollute the global namespace

like image 178
Renan Tomal Fernandes Avatar answered Oct 11 '22 16:10

Renan Tomal Fernandes