1

I want to use the code form this Plunk.

It has a directive:

myApp.directive('fileModel', ['$parse', function ($parse) {

and a service

myApp.service('fileUpload', ['$http', function ($http) {

and the example injects into the controller thusly:

myApp.controller('myCtrl', ['$scope', 'fileUpload', function($scope, fileUpload){

I have this:

angular
    .module('Dashboard')
    .controller('DashboardController', DashboardController);

and

function DashboardController($rootScope, $scope, $http, 
                             $interval, $state, $location)
{

But I can't figure out how to inject the file upload into my controller :-(

8
  • 1
    what is module name for fileUpload service? Commented Jan 22, 2017 at 12:49
  • Isn't it in the Plunkr? My module is called UplaodStuff Commented Jan 22, 2017 at 12:51
  • so try this angular.module('Dashboard',['UplaodStuff ']) ... and function DashboardController($rootScope, $scope, $http, $interval, $state, $location,fileUpload)` and also inject UplaodStuff js file before Dashboard module js. { Commented Jan 22, 2017 at 12:54
  • 1
    because you define fileUpload service in separate module. see this stackoverflow.com/questions/19109291/… Commented Jan 22, 2017 at 12:58
  • 1
    yes you can. change module name to own module name. Commented Jan 22, 2017 at 13:01

1 Answer 1

1

Try like this. i think your problem is for module name.i define fileUpload service in same module for DashboardController

  var myApp = angular.module("yourAppName",[]);
  myApp.directive('fileModel', ['$parse', function ($parse) {
  ...

  myApp.service('fileUpload', ['$http', function ($http) {
  ...

 myApp.controller('DashboardController', DashboardController);


function DashboardController($rootScope, $scope, $http, 
                         $interval, $state, $location,fileUpload)
   {
Sign up to request clarification or add additional context in comments.

2 Comments

That works perfectly. I finally found a reasonably simple way to upload files to the server.
Glad to help you :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.