3

Anyone know why I'm getting Unknown provider on this Angular code ?

I am using the Angular File Upload directive and are using this example :

http://www.mono-software.com/blog/post/Mono/233/Async-upload-using-angular-file-upload-directive-and-net-WebAPI-service/

Just cannot seem to figure out why I'm getting this error...

module.js file :

angular.module('photoApp', ['ngRoute']);

scripts.js file :

    // configure our routes
    angular.module('photoApp').config(function ($routeProvider) {
    $routeProvider

            // route for the home page
            .when('/', {
                templateUrl: 'Pages/home.html',
                controller: 'mainController'
            })

            // route for the contact page
            .when('/uploadphoto', {
                templateUrl: 'Pages/photoupload.html',
                controller: 'photoUploadController'
            });
});

// create the controller and inject Angular's $scope



    angular.module("photoApp").controller('photoUploadController',
    function ($scope, $http, $timeout, $upload) {
        $scope.message = 'Upload your photo';

        $scope.upload = [];
        $scope.fileUploadObj = { testString1: "Test string 1", testString2: "Test string 2"         
    };

        $scope.onFileSelect = function($files) {
            //$files: an array of files selected, each file has name, size, and type.
            for (var i = 0; i < $files.length; i++) {
                var $file = $files[i];
                (function(index) {
                    $scope.upload[index] = $upload.upload({
                        url: "./api/file/upload", // webapi url
                        method: "POST",
                        data: { fileUploadObj: $scope.fileUploadObj },
                        file: $file
                    }).progress(function(evt) {
                        // get upload percentage
                        console.log('percent: ' + parseInt(100.0 * evt.loaded / evt.total));
                    }).success(function(data, status, headers, config) {
                        // file is uploaded successfully
                        console.log(data);
                    }).error(function(data, status, headers, config) {
                        // file failed to upload
                        console.log(data);
                    });
                })(i);
            }
        }

        $scope.abortUpload = function(index) {
            $scope.upload[index].abort();
        }
    });
halfer
  • 19,824
  • 17
  • 99
  • 186
Terje Nygård
  • 1,233
  • 6
  • 25
  • 48

1 Answers1

5

Just add the dependancy on angularFileUpload and be sure to reference the JS files in the correct order, and you should be good to go

index.html

<script src="angular-file-upload-shim.min.js"></script> 
<script src="angular.min.js"></script>
<script src="angular-file-upload.min.js"></script> 

module.js

angular.module('photoApp', ['ngRoute', 'angularFileUpload']);
domokun
  • 3,013
  • 3
  • 29
  • 55
  • Wow.. thanks mate :) So... the same goes for f.eks. a dataFactory.js file i'm using for rest-service communication ? – Terje Nygård Jun 24 '14 at 20:17
  • Well, it depends on *what* this `dataFactory.js` is. As a rule of thumb, if you're adding a new "functionality" to your app, then you will have to list it as a dependency. See https://docs.angularjs.org/guide/di – domokun Jun 25 '14 at 07:52