{"ast":null,"code":"import { __decorate } from \"tslib\";\nimport { Component } from '@angular/core';\nimport { FormControl, FormGroup, Validators } from \"@angular/forms\";\nimport { finalize } from \"rxjs\";\nlet ImagesComponent = class ImagesComponent {\n constructor(storage, imageService) {\n this.storage = storage;\n this.imageService = imageService; // imgBaseUrl: string = 'http://127.0.0.1:8887/uploadImage.jpg';\n // imgUrl: string = '';\n\n this.imgSrc = '';\n this.selectedImage = null;\n this.form = new FormGroup({\n imageUrl: new FormControl('', Validators.required)\n });\n this.isSubmitted = false;\n this.hasValue = false;\n }\n\n ngOnInit() {\n this.resetForm();\n }\n\n showPreview(event) {\n if (event.target.files && event.target.files[0]) {\n const reader = new FileReader();\n\n reader.onload = e => this.imgSrc = e.target.result;\n\n reader.readAsDataURL(event.target.files[0]);\n console.log(\"url\", event.target.files[0].url);\n this.hasValue = true;\n this.selectedImage = event.target.files[0];\n } else {\n this.imgSrc = 'http://127.0.0.1:8887/uploadImage.jpg';\n this.selectedImage = null;\n }\n }\n\n onSubmit(formValue) {\n this.isSubmitted = true;\n\n if (this.form.valid) {\n var filePath = `images/${this.selectedImage.name}_${new Date().getTime()}`;\n const fileRef = this.storage.ref(filePath);\n this.storage.upload(filePath, this.selectedImage).snapshotChanges().pipe(finalize(() => {\n fileRef.getDownloadURL().subscribe(url => {\n formValue['imageUrl'] = url;\n console.log(\"URL => \", formValue['imageUrl']);\n this.imageService.insertImageDetails(formValue['imageUrl']);\n console.log(\"upload done\");\n this.resetForm();\n });\n })).subscribe();\n }\n }\n\n get formControls() {\n return this.form.get('controls');\n }\n\n resetForm() {\n this.form.reset();\n this.form.setValue({\n imageUrl: ''\n });\n this.imgSrc = 'http://127.0.0.1:8887/uploadImage.jpg';\n this.selectedImage = null;\n this.isSubmitted = false;\n }\n\n};\nImagesComponent = __decorate([Component({\n selector: 'app-images',\n templateUrl: './images.component.html',\n styleUrls: ['./images.component.css']\n})], ImagesComponent);\nexport { ImagesComponent };","map":null,"metadata":{},"sourceType":"module"}