javascript - maintainable way of injecting dependencies in angularjs -


i wondering how can inject dependencies in more readable way in angular. more interested in amd(requirejs) way. following:

define(function (require) {     var moduleone = require("moduleone"),         moduletwo = require("moduletwo");      var thismodule = (function () {           // code here     })();      return thismodule; }); 

is possible inject dependencies above way in angularjs or there better way current way in angularjs?

from angular js official website

angular modules solve problem of removing global state application , provide way of configuring injector. as opposed amd or require.js modules, angular modules don't try solve problem of script load ordering or lazy script fetching. these goals orthogonal , both module systems can live side side , fulfil goals.

hence, purpose of both libraries(requirejs , angularjs) totally different. dependency injection system built angularjs deals objects needed in component; while dependency management in requirejs deals modules or, javascript files.

in requirejs, objects of loaded modules cached , served when same modules requested again. on other hand, angularjs maintains injector list of names , corresponding objects. in case, object served whenever referenced using registered name.

generally inject dependencies in angularjs like

somemodule.controller('mycontroller', function($scope,greeter){  }); 

if want alternative way inject dependencies in angularjs, may like.

var mycontroller = function($scope, greeter) {   // ... } mycontroller.$inject = ['$scope', 'greeter']; somemodule.controller('mycontroller', mycontroller); 

hope helps!


Comments

Popular posts from this blog

facebook - android ACTION_SEND to share with specific application only -

python - Creating a new virtualenv gives a permissions error -

javascript - cocos2d-js draw circle not instantly -