Basics of AngularJS Controller defination syntax -


i new angularjs , not familar javascript, jquery hence may asking silly question.

while going through angularjs sample application, notice things :

define(['app'], function (app) { var customerscontroller = function ($scope, $location, $filter, dataservice,   modalservice) {...} app.register.controller('customerscontroller', ['$scope', '$location', '$filter', 'dataservice', 'modalservice', customerscontroller]); 

i not understand complete syntax, example not know line means or do?

define(['app'], function (app) 

where can learn basic stuff? tutorial links helpful. in advance help.

that's requirejs semantics. in requirejs define creates module. here declare module, in case controller, first array dependencies module, in case it's app, our angular app definition. dependencies (first parameter of define, array) resolved , passed function (our controller), here app passed controller:

define(['app'], function (app) {

the line below creates function acting our controller: var customerscontroller = function ($scope, $location, $filter, dataservice, modalservice) {}

the above angular controller definition, dependencies passed controller. below hook controller function app dependency requirejs brought in us. we're telling angular create controller called customerscontroller, second parameter, array strings defining controllers dependencies hard coded strings, make script minification safe, since string won't tampered minifier, example in angular if controller's scope gets minified s, break app.

app.register.controller('customerscontroller', ['$scope', '$location', '$filter', 'dataservice', 'modalservice', customerscontroller]);

the whole point of approach allow lazy (on demand) loading of modules/controllers in angular, if you're not building huge app there's no need. 1 found approach dan wahlin extremely helpful.

here more articles you:

angularjs - controllers, dependencies, , minification

requirejs api


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -