Shane
Shane

Reputation: 5677

Can anyone tell me how this works?

(function(ng, app){
    app = angular.module('app', []);

    app.config(function($provide) {
        $provide.constant('town', 'Burlington');
    });

    app.constant('name', 'Rob F.');

    app.controller('MainCtrl', [
        'name', 'town',
        function MainCtrl(name, town) {
            this.getName = function() {
                return name;
            };

            this.getTown = function() {
                return town;
            };
        }
    ]);
}(angular));

http://jsfiddle.net/founddrama/RvXn3/

I see that we are passing angular as a argument, but the IIFE collects ng, app. Can anyone tell me what is ng, app here? I don't see ng used any where?

Upvotes: 1

Views: 91

Answers (1)

AngularLover
AngularLover

Reputation: 364

And you dont have to use these arguments. You can run this code without the parameters. Then the app variable will be declared implicitly.s No need to use these Parameters :)

Upvotes: 1

Related Questions