angularjs - Different ways to inject dependencies -
when writing ex. directives can reference/inject dependencies both in directive factory function like:
app.direcive('directivename', function ($http) { ... };
or in controller
app.directive('directivename, function () { ... controller: function ($http), ... };
also today i've read post made me think what's difference between 2 approaches?
there many ways. none right or wrong. style. use 1 way project, clarity , consistency.
this suggest:
yourcontroller.$inject = ['http']; function yourcontroller($http) {} function yourdirectivename() { return { controller: yourcontroller, controlleras: 'vm', bindtocontroller: true } } app.directive('yourdirectivename', yourdirectivename);
Comments
Post a Comment