2014-06-24 31 views
3

任何人都知道爲什麼我在這個Angular代碼上得到未知提供者?

我使用的角度文件上傳指令,並使用這些例子:

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

回答

5

只需添加上的扶養和angularFileUpload一定要引用正確的順序JS文件,你應該是好去

的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']); 
+0

哇..感謝隊友:)所以... f.eks也是如此。我用於休息服務通信的dataFactory.js文件? –

+0

那麼,它取決於*這個'dataFactory.js'是什麼。作爲一個經驗法則,如果您要爲應用程序添加新的「功能」,則必須將其列爲依賴項。請參閱https://docs.angularjs.org/guide/di – domokun

相關問題