|
|
@@ -2,7 +2,7 @@ import { Component, OnInit } from "@angular/core";
|
|
|
import { FileUploader, FileLikeObject } from "ng2-file-upload";
|
|
|
import { concat } from "rxjs";
|
|
|
import { FormBuilder, FormGroup } from "@angular/forms";
|
|
|
-import { HttpClient } from "@angular/common/http";
|
|
|
+import { HttpClient, HttpEventType } from "@angular/common/http";
|
|
|
|
|
|
@Component({
|
|
|
selector: "app-payment-requirement",
|
|
|
@@ -13,34 +13,40 @@ export class PaymentRequirementComponent implements OnInit {
|
|
|
title: string = "Formulario de requisición de pago";
|
|
|
|
|
|
form: FormGroup;
|
|
|
- public uploader: FileUploader = new FileUploader({});
|
|
|
- public hasBaseDropZoneOver: boolean = false;
|
|
|
+ fileData: File = null;
|
|
|
+ previewUrl: any = null;
|
|
|
+ fileUploadProgress: string = null;
|
|
|
+ uploadedFilePath: string = null;
|
|
|
+ constructor(private http: HttpClient) {}
|
|
|
|
|
|
ngOnInit() {}
|
|
|
|
|
|
- constructor(public fb: FormBuilder, private http: HttpClient) {
|
|
|
- this.form = this.fb.group({
|
|
|
- name: [""],
|
|
|
- avatar: [null]
|
|
|
- });
|
|
|
+ fileProgress(fileInput: any) {
|
|
|
+ this.fileData = <File>fileInput.target.files[0];
|
|
|
+ this.preview();
|
|
|
}
|
|
|
|
|
|
- uploadFile(event) {
|
|
|
- const file = (event.target as HTMLInputElement).files[0];
|
|
|
- this.form.patchValue({
|
|
|
- avatar: file
|
|
|
- });
|
|
|
- this.form.get("avatar").updateValueAndValidity();
|
|
|
- }
|
|
|
+ preview() {
|
|
|
+ // Show preview
|
|
|
+ var mimeType = this.fileData.type;
|
|
|
+ if (mimeType.match(/image\/*/) == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
|
|
|
- submitForm() {
|
|
|
- var formData: any = new FormData();
|
|
|
- formData.append("name", this.form.get("name").value);
|
|
|
- formData.append("avatar", this.form.get("avatar").value);
|
|
|
+ var reader = new FileReader();
|
|
|
+ reader.readAsDataURL(this.fileData);
|
|
|
+ reader.onload = _event => {
|
|
|
+ this.previewUrl = reader.result;
|
|
|
+ };
|
|
|
+ }
|
|
|
|
|
|
- this.http.post("http://localhost:4000/api/create-user", formData).subscribe(
|
|
|
- response => console.log(response),
|
|
|
- error => console.log(error)
|
|
|
- );
|
|
|
+ onSubmit() {
|
|
|
+ const formData = new FormData();
|
|
|
+ formData.append("file", this.fileData);
|
|
|
+ this.http.post("url/to/your/api", formData).subscribe(res => {
|
|
|
+ console.log(res);
|
|
|
+ //this.uploadedFilePath = res.data.filePath;
|
|
|
+ alert("SUCCESS !!");
|
|
|
+ });
|
|
|
}
|
|
|
}
|