Marc, Controllers are not services in Angular.js, they are distinct. If you really need to construct a new controller, you can use the $controller service (which can be injected where you are trying to inject the controller currently). I suspect that you're misunderstanding what you should be doing, though, so why don't you clarify what you're attempting to accomplish?
Also, don't name any of your own stuff with the $ prefix - it makes it harder to tell what's an angular native thing and what's an application or library thing. On Thu, Feb 6, 2014 at 12:30 PM, Marc B <[email protected]> wrote: > Hello, > > I have a controller that contains a function I want to use in a directive. > How can I inject that controller into the directive? > > I tried > > .directive("cstUpload", > function(itemController){ // <== want to inject "itemController" in > this directive > return { > restrict: "AE", > link: function(scope,element,attrs){ > > element[0].addEventListener("change",function(attrs){itemController.uploadFiles(attrs);}); > } > } > } > ); > > which gives (in Firebug console) > > Error: [$injector:unpr] Unknown provider: itemControllerProvider <- > itemController <- cstUploadDirective > http://errors.angularjs.org/1.2.10/$injector/unpr?p0=itemControllerProvider%20%3C-%20itemController%20%3C-%20cstUploadDirective > > > directive("cstUpload", > function($itemController){ > > gives > Error: [$injector:unpr] Unknown provider: $itemControllerProvider <- > $itemController <- cstUploadDirective > > directive("cstUpload",["$itemController" > function($itemController){ > ... > ]) > > gives > Error: [$injector:unpr] Unknown provider: $itemControllerProvider <- > $itemController <- cstUploadDirective > > but these don't work. The error occurs in AngularJS line 9400 so it's hard > for me to figure out what part of my code generates the error. No such > thing as a stacktrace in FireBug. > > Thanks, > > Marc > > -- > You received this message because you are subscribed to the Google Groups > "AngularJS" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to [email protected]. > Visit this group at http://groups.google.com/group/angular. > For more options, visit https://groups.google.com/groups/opt_out. > -- chrisrhoden -- You received this message because you are subscribed to the Google Groups "AngularJS" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/angular. For more options, visit https://groups.google.com/groups/opt_out.
