Upload Image
The UploadImageComponent is a simple Angular component for uploading and previewing images. It allows users to select an image file, emits the selected file for further processing, and displays a preview of the image. This component is ideal for use cases such as profile picture uploads or image attachments in forms.
How to use the component in your app :
import the component :
import {UploadImageComponent} from '@tradinos/cms-frontend-form';The selector for component , like it :
<lib-cms-upload-image></lib-cms-upload-image>Features
Image Upload:
Allows users to upload an image file through an input element.
Real-Time Image Preview:
Displays a preview of the selected image file using
FileReader.
Event-Driven:
Emits the selected image file through the
imageChangedoutput for further processing.
Disabled State:
Supports disabling the input field to prevent user interaction when required.
Custom Configuration:
Accepts an
ImageConfigurationinput for additional customization.
Inputs
Input
Type
Description
Default Value
configuration
ImageConfiguration
Defines additional configuration for image upload behavior (e.g., file type restrictions).
-
disabled
boolean
Disables the input field when set to true, preventing user interaction.
false
This is the options in ImageConfiguration type:
Outputs
Output
Type
Description
imageChanged
EventEmitter<File>
Emits the selected image file whenever a new file is uploaded.
For example:
Methods
1. onFileSelected(event: any): void
Description:
Handles the file selection event from the input element.
Emits the selected image file through the
imageChangedoutput.Generates a base64 preview of the image file for display.
Parameters:
event: The file selection event containing the file details.
Last updated