ganjeii ganjeii - 1 year ago 82
AngularJS Question

AngularJS When to Use Controller-level named functions?

Looking through tutorials and others' code. I don't understand why on some controllers a named function is used and on some there is no name?

eg. name is used on function

named function

eg. name is not used on function

name not used

My question is basically the same as the duplicate listed but the answer on my question I feel is a better answer than in the referenced "duplicate post."

Answer Source

First onee will create global namespace, which can be accessed globally

eventsApp.controller('CookieStoreSampleController,function CookieStoreSampleController($scope,$cookieStore){

This way of declaring controllers in many examples but that shouldn't be used in applications.

Second one scopes the Controller to that module instance which uses the array notation that will survive minification.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download