2021-08-23 15:18:43 +01:00
|
|
|
import { Injectable } from '@angular/core';
|
2021-08-23 16:01:07 +01:00
|
|
|
import { FileType } from 'src/app/models/fileType';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
interface createInput {
|
|
|
|
|
type?: string
|
|
|
|
|
accept: typeof FileType[]
|
|
|
|
|
}
|
2021-08-23 15:18:43 +01:00
|
|
|
|
|
|
|
|
@Injectable({
|
|
|
|
|
providedIn: 'root'
|
|
|
|
|
})
|
|
|
|
|
export class FileLoaderService {
|
|
|
|
|
|
2021-08-23 16:01:07 +01:00
|
|
|
nice : typeof FileType
|
2021-08-23 15:18:43 +01:00
|
|
|
constructor() { }
|
|
|
|
|
|
|
|
|
|
|
2021-08-24 11:15:13 +01:00
|
|
|
createInput({accept, type = 'file'}:createInput): HTMLInputElement {
|
2021-10-08 15:37:24 +01:00
|
|
|
|
2021-08-23 15:18:43 +01:00
|
|
|
let input = document.createElement('input');
|
2021-08-24 11:15:13 +01:00
|
|
|
input.type = type || 'file';
|
|
|
|
|
input.accept = accept.join(', ')
|
2021-10-08 15:37:24 +01:00
|
|
|
|
2021-08-23 15:18:43 +01:00
|
|
|
// input.onchange = () => {
|
|
|
|
|
// // you can use this method to get file and perform respective operations
|
|
|
|
|
// let files = Array.from(input.files);
|
2022-04-28 09:32:27 +01:00
|
|
|
//
|
2021-08-23 15:18:43 +01:00
|
|
|
// };
|
|
|
|
|
|
2021-10-08 15:37:24 +01:00
|
|
|
|
2021-08-23 15:18:43 +01:00
|
|
|
input.click();
|
|
|
|
|
|
|
|
|
|
return input
|
2021-10-08 15:37:24 +01:00
|
|
|
|
|
|
|
|
|
2021-08-23 15:18:43 +01:00
|
|
|
}
|
2021-08-23 16:01:07 +01:00
|
|
|
|
|
|
|
|
getFirstFile(input: HTMLInputElement) {
|
|
|
|
|
let files = Array.from(input.files);
|
|
|
|
|
return files[0]
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-23 15:18:43 +01:00
|
|
|
}
|