我知道这是一个普遍的问题,但我没有在Angular 2上传文件.我试过了
1)http://valor-software.com/ng2-file-upload/和
2)http://ng2-uploader.com/home
......但失败了.有人在Angular上传过文件吗?你用了什么方法?怎么办?如果提供任何示例代码或演示链接,我们将非常感激.
我是Angular的初学者,我想知道如何创建Angular 5 文件上传部分,我试着找到任何教程或文档,但我什么都没看到.对此有何看法?我正在尝试ng4文件,但它不适用于Angular 5
我对打字稿和网页开发很新,所以如果我的代码很糟糕,我很抱歉.无论如何,我在显示配置文件图片上传的"预览图像"时遇到问题.我正在使用ng2-file-upload将我的图像上传到服务器,该部分工作正常.在我点击上传按钮之前,我想在选择后立即在页面上显示所选图像.目前我试图通过从HTMLImageElement检索src属性来显示图像,但src属性似乎是空的.
import { Component, OnInit } from '@angular/core';
import { FileUploader } from 'ng2-file-upload/ng2-file-upload';
const URL = 'http://localhost:4200/api/upload';
@Component({
selector: 'app-view-profile',
templateUrl: './view-profile.component.html',
styleUrls: ['./view-profile.component.css']
})
export class ViewProfileComponent implements OnInit {
constructor() { }
public uploader: FileUploader = new FileUploader({url: URL, itemAlias: 'newProfilePicture'});
title: string;
previewImage: any;
tempImage: any;
source: string;
imagePreview(input)
{
document.getElementById("previewImage").style.display="block";
console.log("Image is selected")
this.previewImage = document.getElementById("previewImage");
console.log(this.previewImage);
this.source = (<HTMLImageElement>document.getElementById('previewImage')).src
console.log("Image Source: " + this.source + " Should be inbetween here");
//var reader = new …Run Code Online (Sandbox Code Playgroud)