3

任何人都知道为什么我在这个 Angular 代码上得到 Unknown provider 吗?

我正在使用 Angular File Upload 指令并使用以下示例:

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

只是似乎无法弄清楚为什么我会收到这个错误......

module.js 文件:

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

scripts.js 文件:

    // 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();
        }
    });
4

1 回答 1

5

只需添加依赖项angularFileUpload并确保以正确的顺序引用 JS 文件,您应该一切顺利

索引.html

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

模块.js

angular.module('photoApp', ['ngRoute', 'angularFileUpload']);
于 2014-06-24T15:13:57.980 回答