0

I have a controller like this :

  .controller('candidatureStartCtrl', function ($scope, $parse, fileUploadCtrl) {

//...code
      fileUploadCtrl.uploadFile($scope.identityDocUpload);
//...code
}

in candidatureStartCtrl I'm calling another controller which is fileUploadCtrl to use its function uploadFile().

but I get this error in console even though I imported the fileUploadCtrl js in the index.html :

 Error: [$injector:unpr] Unknown provider: fileUploadCtrlProvider <- fileUploadCtrl <- CandidatureStartCtrl

this is a fiddle with the same concept :

http://jsfiddle.net/7tzXh/143/

How can I solve this ?

Renaud is Not Bill Gates
  • 1,684
  • 34
  • 105
  • 191

2 Answers2

1

You cannot inject controllers directly without using $controller as mentioned in one of the comments to the question. If you need to share data, you can use factory or service.

Please find the working fiddle here:

http://jsfiddle.net/7tzXh/144/

Adarsh Konchady
  • 2,577
  • 5
  • 30
  • 50
  • Thanks I actually used that solution before and I wanted to ask if I can to use a controller inside another but since controllers get garbage collected on route changes using a service/factory is the best idea. – Renaud is Not Bill Gates Apr 20 '16 at 11:25
0

$controller is used to inject a controller into another. I've created a simple fiddle to make it clear.

Shreyas
  • 1,927
  • 17
  • 34