Upload File
The UploadFileComponent is a versatile Angular component designed to handle file uploads. It supports advanced features like automatic file upload, preloading media files, and integration with the PrimeNG FileUpload component. This component is ideal for applications requiring customizable and dynamic file upload functionality.
How to use the component in your app :
import the component :
import {UploadFileComponent} from '@tradinos/cms-frontend-form';The selector for component , like it :
<lib-cms-upload-file></lib-cms-upload-file>Features
Advanced and Basic Modes:
Supports multiple modes (
'advanced'or'basic') to control the file upload UI.
Preload Media:
Automatically loads preconfigured media files into the upload list.
Event-Driven Updates:
Emits events (
filesChanged) whenever files are added, removed, or updated.
Customizable UI:
Allows custom icons, styles, and configurations for the file upload interface.
Multiple File Support:
Handles single or multiple file uploads based on the
configuration.multipleproperty.
Automatic Uploads:
Automatically uploads files when
autois enabled.
Dynamic Updates:
Reactively updates the upload list and emits changes on file selection or removal.
Inputs
Input
Type
Description
Default Value
mode
FileUpload['mode']
Specifies the upload mode ('advanced' or 'basic').
'advanced'
configuration
FileConfiguration
Defines the file upload behavior (e.g., multiple files, restrictions).
-
styleClass
FileUpload['styleClass']
Custom CSS class for styling the file upload component.
-
chooseIcon
string
Custom icon for the "Choose File" button.
-
auto
boolean
Enables automatic upload when set to true.
false
loading
boolean | null
Indicates whether the component is currently in a loading state, typically used to show loading indicators.
false
media
Media[]
Array of preloaded media files to initialize in the file upload list.
[]
This is the options in FileConfiguration type:
Outputs
Output
Type
Description
filesChanged
EventEmitter<File | File[] | null>
This output emits whenever the file list changes, whether files are added, removed, or updated
The emitted value can be:
A single file if
multipleisfalsein the configuration.An array of files if
multipleistrue.nullif the file list is empty.
For example:
Methods
1. ngAfterViewInit()
Description:
Lifecycle hook that checks for preloaded media files and processes them after the component view is initialized.
Parameters: None.
Returns:
void.
2. checkFileInput(): Promise<void>
Description:
Loads media files specified in the
mediainput and converts them into file objects for display in the file upload list.
Parameters: None.
3. updateFileUploadFiles()
Description:
Updates the PrimeNG
FileUploadcomponent with the selected files and triggers change detection.
Parameters: None.
4. onSelect()
Description:
Handles the selection of new files and emits the updated file list through the
filesChangedoutput.
Parameters: None.
5. onRemove()
Description:
Handles the removal of files and emits the updated file list through the
filesChangedoutput.
Parameters: None.
6. emitChanges()
Description:
Emits the updated file list or a single file (based on the
multipleconfiguration) through thefilesChangedoutput.Clears the file upload list if
autoupload is enabled.
Parameters: None.
Last updated