angularjs - Inject constant into link function along with parent controller -


i'm using following syntax inject parent controller custom directive's link function , i'd inject constant well.

angular.module('mymodule')  .constant('mydefaults', {   key: value })  .directive('mydirective', function () {      return {          require:'^myparentdirective',         restrict: 'ea',         scope: {},          link: function ($scope, $element, $attrs, myparentdirectivectrl, mydefaults) {             ... link funciton code ...         }     } } 

unfortunately, mydefaults not defined , if swap order myparentdirectivectrl undefined.

i thought order didn't matter, presumably because think can call parent controller when inject it, doesn't need called same name in actual parent directive's controller. so, have 4th parameter of link function? , why ignoring injected after it?

thanks.

if want inject service , factory or controller should directive not link.inject dependancies directive, work fine try using below :

angular.module('mymodule')  .constant('mydefaults', { key: value })  .directive('mydirective', ['myparentdirectivectrl', 'mydefaults', function (myparentdirectivectrl, mydefaults) {  return {      require: '^myparentdirective',     restrict: 'ea',     scope: {},      link: function ($scope, $element, $attrs) {         // here can use services injected directive.         //...link funciton code...     } }; }]); 

Comments

Popular posts from this blog

python - Mongodb How to add addtional information when aggregating? -

java - Spring Data JPA: Why findOne(id) executing delete query internally? -

ruby - Net::HTTP extremely slow responses for HTTPS requests -