2

我是 AngularJS 的新手,我正在尝试使用 ng-file-upload 上传图像

我的任务是将 Ionic 应用程序转换为网络应用程序,因此我必须重用相同的路线。

<button ngf-select="upload($file)" ng-model="file">Select</button>


    $scope.upload = function (file) {
      $scope.event.headerPictures.push(file);
      console.log($scope.event);
      console.log(file);
      if (file && !file.$error) {
        Upload.upload({
            url: $config.baseUrl + '/api/event/upload-picture',
            method: "POST", 
            headers: {"Authorization" : "token=" + userService.getToken()},
            file: file,
        }).then(function (resp) {
            console.log('Success ' + resp.config.data.file.name + 'uploaded. Response: ' + resp.data);
        }, function (resp) {
            console.log('Error status: ' + resp.status);
        }, function (evt) {
            var progressPercentage = parseInt(100.0 * evt.loaded / evt.total);
            console.log('progress: ' + progressPercentage + '% ' + evt.config.data.file.name);
        });
      };
    };

我仍然遇到许多不同语法的相同错误:

Error: Unexpected field

有人能告诉我我错过了什么吗?

4

1 回答 1

0

很抱歉猜测答案,但出现意外的字段错误,我认为您的代码行带有额外的逗号分隔符是问题所在。

file: file,应该file: file

希望这可以帮助。我会对此发表评论,但我的声誉太低,无法发表评论:)

于 2015-11-06T00:02:53.753 回答