Interpreting the Setupmoduleloader function of Angularjs

Source: Internet
Author: User

Http://www.cnblogs.com/whitewolf/p/angular-module-declare-and-get.html

Reading the above article, I read the code, the following is a personal understanding, such as please correct

/** * Created by Administrator on 2016/10/15.*/functionSetupmoduleloader (window) {//... Omit part of the code    //Note that angular.module (' name ', [require]) defines and obtains a new module    //and Anguular.module (' name ') to get an existing module    //determines whether the object obj has a Name property, exists directly, or returns the name, otherwise calls the function factory sets the property and returns the property    functionensure (obj, name, factory) {returnObj[name] | | (Obj[name] =Factory ()); }    //ensure that the angular property exists under the Window object    varAngular = ensure (window, ' angular '), Object); //ensure that the module attribute exists under angular    returnEnsure (angular, ' module ',function() {        varModules = {}; return functionmodule (name, requires, CONFIGFN) {//if the module is named hasOwnProperty, error: Not a valid name            varAssertnothasownproperty =function(name, context) {if(name = = = ' hasOwnProperty ')) {                    ThrowNgminerr (' Badname ', ' hasownproperty is not a valid {0} name ', context);            }            }; //ensure module name is not ' module 'Assertnothasownproperty (Name, ' module ')); //if the module is defined, and the name is duplicated with the existing module name, the original module is empty, i.e. the module with the same name will be overwritten by the module defined later            if(Requires &&Modules.hasownproperty (name)) {Modules[name]=NULL; }            //if the module name already exists, return the instance of the module directly, otherwise define a new module            returnEnsure (modules, name,function() {                //to define a new module, there is no require parameter, error; Note require is the definition of [], and no this parameter indicates that the fetch                if(!requires) {                    Throw$INJECTORMINERR (' Nomod ', ' Module ' {0} ' is not available! You either misspelled "+" of the module name or forgot to load it. If registering a module ensure that you "+" Specify the dependencies as the second argument. ", name); }                varInvokequeue = []; varRunblocks = []; varConfig = invokelater (' $injector ', ' Invoke '); //Module Instances                varModuleinstance ={_invokequeue:invokequeue, _runblocks:runblocks, requires : Requires, Name:name, Provider:invokelater (' $provide ', ' provider '), Factory:invokelater (' $provide ', ' factory '), Service:invokelater (' $provide ', ' service '), Value:invokelater (' $provide ', ' value '), Constant:invokelater (' $provide ', ' constant ', ' unshift '), Animation:invokelater (' $animateProvider ', ' register '), Filter:invokelater (' $filterProvider ', ' register '), Controller:invokelater (' $controllerProvider ', ' register '), Directive:invokelater (' $compileProvider ', ' directive '), Config:config, run:function(block) {Runblocks.push (block); return  This;                }                }; if(CONFIGFN) {config (CONFIGFN); }                returnmoduleinstance; //Invokelater Returns a function that is invoked when the module is used to create a controller, service, and so on, pushes data into the invokequeue, and returns an instance of the module                //That's why we can write this in Angularjs.                //angular.module (' Somemoudule ', [' require1 '])                //. Controller (...)                //. Directive (...)                //instead of writing the variable name of the module name every time, just like this                //var myapp=angular.module (... );                //Myapp.controller (...);                //myaap.directive (...);                functionInvokelater (provider, method, InsertMethod) {return function() {Invokequeue[insertmethod|| ' Push '] ([Provider, method, arguments]); returnmoduleinstance;                };        }            });    }; });}

Interpreting the Setupmoduleloader function of Angularjs

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.