AngularFormly文件上传-仅显示文件路径,而非文件内容。
创始人
2024-10-24 22:01:55
0

此问题的解决方法是在Formly的模板选项中使用ng-file-upload插件,并在fileUpload中使用onSuccess和onError来设置上传文件的路径。下面是代码示例:

在Angular应用程序中安装ng-file-upload插件:

npm install ng-file-upload --save

在模块中导入ng-file-upload:

import { ngFileUploadModule } from 'ng-file-upload';

在Formly的模板选项中使用ng-file-upload插件:

import { Component } from '@angular/core';
import { FileUploader } from 'ng-file-upload';

@Component({
  selector: 'my-app',
  template: `
  
  `,
})
export class AppComponent {
  public uploader: FileUploader = new FileUploader({ url: 'uploadUrl' });

  public fields = [
    {
      key: 'document',
      type: 'file',
      templateOptions: {
        label: 'Select a file',
        required: true,
        type: 'file',
      },
      parser: (val) => this.uploader.queue[0]._file.name,
      validators: {
        fileCheck: {
          expression: (control) => {
            return !!control.value;
          },
          message: '$viewValue + " is not a valid file"',
        },
      },
    },
  ];

  public model = {};

  public form = new FormGroup({});
}

在fileUpload中使用onSuccess和onError来设置上传文件的路径:

import { ngFileUploadModule } from 'ng-file-upload';

@Component({
    selector: 'file-upload',
    template: `
        
        
    `,
    providers: [ ng2UploaderService ]
})

export class FileUpload{
    public uploader:FileUploader = new FileUploader({url:'http://localhost:10050/upload'});
    public async uploadedPath: string;

    constructor(protected ng2Uploader: ng2UploaderService) {
      this.up

相关内容

热门资讯

玩家必看科普!we-poker... 玩家必看科普!we-poker辅助器(辅助挂)都是有挂(有挂细节辅助教程)1、免费辅助多个强度级别选...
玩家必看攻略!德普之星辅助软件... 玩家必看攻略!德普之星辅助软件(辅助挂)好像是真的有挂(有挂解惑辅助方法)1、免费辅助多个强度级别选...
大家学习交流!hhpoker作... 大家学习交流!hhpoker作弊实战视频(辅助挂)真是真的有挂(有挂攻略辅助插件)1、超多福利:超高...
如何分辨真伪!wepoker好... 如何分辨真伪!wepoker好友房开挂(辅助挂)其实有挂(存在有挂辅助技巧);1、模拟器是什么优化,...
重大消息!wepoker辅助插... 重大消息!wepoker辅助插件功能(辅助挂)确实是有挂(有挂秘笈辅助软件)1、打开软件启动之后找到...
带你了解!agpoker辅助(... 带你了解!agpoker辅助(辅助挂)一贯有挂(有挂方式辅助工具)1、进入到是否有挂之后,能看到左侧...
必看攻略!pokemmo辅助器... 必看攻略!pokemmo辅助器脚本下载(辅助挂)竟然真的是有挂(新版有挂辅助插件)能透视中分为三种模...
发现一款!hhpoker到底可... 发现一款!hhpoker到底可以作弊码(辅助挂)其实真的有挂(有挂秘籍辅助app)所有人都在同一条线...
普及知识!pokerworld... 普及知识!pokerworld破解版下载(辅助挂)一贯真的是有挂(有挂教学辅助工具)1、免费脚本咨询...
必备科技!哈糖大菠萝软件下载(... 必备科技!哈糖大菠萝软件下载(辅助挂)一贯是有挂(有挂方法辅助脚本)1)辅助插件:进一步探索辅助大陆...