angularjs - Injecting resolves into directive controllers -


i'm using angularui router (0.2.13) , have state defined such

.state('foo', {             template:'<div some-directive></div>',             resolve:{                foo:function(someservice){                    return someservice.something().promise;                }            }) 

and directive this:

app.directive('somedirective', function(){      return {          controller: function(data) {            // want `data` injected resolve...             // if "standalone" controller          }      } }) 

but doesn't work - data parameter causes unknownprovider error. defining directive controller independently , setting name in directive has same result.

i more or less why happening, have 2 questions:

  1. is there way i'm trying do?
  2. should trying it, or have slipped antipattern here?

you can't use resolves in directives, can pass result resolved in state down directive think accomplishes you're looking for.

you'd want update state definition include controller , set parameter on directive:

.state('foo', {     template:'test<div some-directive something="foo"></div>',    url: 'foo',    resolve:{        foo:function(someservice){            return someservice.something();        }    },    controller: function($scope, foo){      $scope.foo = foo;    } }) 

then update directive use parameter:

.directive('somedirective', function(){      return {          controller: function($scope) {            // want `data` injected resolve...             // if "standalone" controller            console.log('$scope.something: '+ $scope.something);          },          scope: {            something: '='          }      }; }) 

here's sample plunker: http://plnkr.co/edit/topmluxc7ghxteyl0ifj?p=preview


Comments

Popular posts from this blog

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

java - Could not locate OpenAL library -

sorting - opencl Bitonic sort with 64 bits keys -