TypeError: Upload.upload is not a function

TypeError: Upload.upload is not a function

我有这个函数,它抛出异常:

$scope.uploadAvatar = function(avatar, user) {
   Upload.upload({
        url: 'api/v1/user' + user.id + '/',
        avatar: avatar,
        method: 'put'
    })
};

TypeError: Upload.upload is not a function

我的脚本包括:

    <script src="/static/js/main.js"></script>
    <script src="/static/js/bootstrap.min.js"></script>
    <script src="/static/js/posts_controller.js"></script>
    <script src="/static/js/jquery.equalheights.min.js"></script>
    <script src="/static/js/video.js/video.js"></script>
    <script src="/static/js/swiper.jquery.min.js"></script>
    <script src="/static/ng-file-upload/FileAPI.js"></script>
    <script src="/static/ng-file-upload/ng-file-upload.js"></script>
    <script src="/static/ng-file-upload/ng-file-upload-all.js"></script>
    <script src="/static/ng-file-upload/ng-file-upload-shim.js"></script>
    <script src="/static/ng-file-upload/ng-file-upload.js"></script>

所以我确实在我的控制器中注入 'Upload' 并在模块中注入 'ngFileUpload' 我的控制器:

myApp.controller('ShowsListController', ['$scope', '$http', '$routeParams', '$location', '$route', 'Upload', function ($scope, $http, $routeParams, $route, Upload) {

    $http.get('/api/v1/shows/').success(function (data) {
        $scope.shows = data;
    });


    $http.get('/check_login/').success(function (data) {
        $scope.mediaurl = data.mediaUrl;
        $scope.user = data;

    });



    $http.get('/api/v1/actors/').success(function (data) {
        $scope.actors = data;
    });

    $http.get('/api/v1/users/').success(function (data) {
        $scope.users = data;
    });


    $scope.uploadAvatar = function (avatar, user) {

        Upload.upload({
            url: 'api/v1/users' + user.id + '/',
            avatar: avatar,
            method: 'put'
        })
    };

}]);

使用这些功能添加我的控制器

在你的控制器声明中,你在 $routeParams 之后注入了 $location 但你忘了在函数中传递它。

由于您使用的是内联数组注释,因此您需要使注释数组与函数声明本身中的参数保持同步。

myApp.controller('ShowsListController', ['$scope', '$http', '$routeParams', '$location', '$route', 'Upload', function ($scope, $http, $routeParams, $location, $route, Upload) {
 // your current code
}

有关详细信息,请参阅 docs