7

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?

0

1 Answer 1

6

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.