首页 > 解决方案 > Angular HttpClient POST 请求在 upLoadByFile 方法 EditorJs 中不起作用

问题描述

我正在尝试将 EditorJs 集成到我的 Angular v10.1.7 应用程序中。但是在图像配置中,我不能使用来自 Angular HttpClient 的 POST 请求将请求发送到我的服务器。

这是代码:

    image: {
      class: ImageTool,
      config: {
        uploader: {
          uploadByFile(file) {
            let formData = new FormData();
            formData.append('image', file, this.title);
            this.httpClient.post(this.NEWS_URL + 'image', formData)
              .subscribe((res) => {
                return {
                  success: res.success,
                  url: res.url,
                };
              });
          },
        },
      },
    },

和错误:

Image Tool: uploading failed because of TypeError: Cannot read property 'post' of undefined

我该如何处理这个问题?是否有任何替代解决方案可以在不使用 Angular HttpClient 的情况下将文件发送到服务器?

标签: javascriptangulartypescripteditorjs

解决方案


推荐阅读