Table of Contents
In this article, I will show how to Image upload in Angular. I will show how to do it, and just follow the steps clearly.
For more updates please do Subscribe via Email:
Implementation
Creating the component for the Upload Image page
- TS componenet
import { Component, OnInit } from '@angular/core';
import { FormsModule } from '@angular/forms';
@Component({
selector: 'app-upload-image',
templateUrl: './upload-image.component.html',
styleUrls: ['./upload-image.component.css']
})
export class UploadImageComponent {
urls = new Array<string>();
detectFiles(event:any) {
this.urls = [];
let files = event.target.files;
if (files) {
for (let file of files) {
let reader = new FileReader();
reader.onload = (e: any) => {
this.urls.push(e.target.result);
}
reader.readAsDataURL(file);
}
}
}
}
- HTML Component
<div class="container">
<p>upload-image works!</p>
<div>
<img *ngFor="let url of urls" [src]="url" class="rounded mb-3" width="180">
</div>
<input type="file" multiple (change)="detectFiles($event)">
</div>
- CSS Component
div.ok { color: green;}
div.bad { color: red;}
Output
Happy Learning..
Thank you for visiting my blog site. Hoping you learn more here. please feel free to comment and suggest if there is need to enhance and update. thank you.
Github : https://github.com/JaveTLupango/AngularCRUD/tree/uploadImage/src/app/upload-image
Related Topics
How to upload image in Angular
In this article, I will show how to Image upload in Angular. I will show how to do it, and just follow the steps clearly. […]
How to call child component method from parent in Angular
In this article, We learn how to call child component method from parent in Angular. I will show how to do it, and just follow […]
How to passing data from mother component to child component in angular.
In this article, we learn how to pass variable from one component to another component. I will show you how, just follow the steps clearly. […]
Implement copy to clipboard in angular using ngx-copypaste
In this article, We learn how to implement the ngx-copypaste in angular for copy to clipboard feature. I will show you how to do it, […]
How to set homepage route URL in angular routing?
In this article, we learn how to setting up homepage route URL in angular routings. I will show you how, just follow the steps clearly. […]
How to setup 404 page in angular routing ?
In this article we learn how to setup 404 page or page not found in angular routing. I will show you how, just follow the […]
How to export customize excel file in Angular Using ExcelJS
In this article, We learn how to export to excel in Angular using ExportJS . I will show you how, just follow the steps clearly. […]
How to Export Excel File in Angular
In this article, We learn how to export data to excel in angular. I will show you how, just follow the steps clearly. For more […]
Implement CKEditor5 Classic in Angular
CKEditor is a WYSIWYG rich text editor which enables writing content directly inside of web pages or online applications. Its core code is written in […]
Implement Toastr Notification in Angular – CodeLife
In this article, We learn how to implement ngx-toastr in Angular. I will show how to do it, and just follow the steps clearly. […]
How to implement SweetAlert2 Notification in Angular
In this article, We learn how to apply and implement SweetAlert2 in Angular. I will show how to do it, and just follow the steps […]
Angular CRUD with .NET Core API
In this article, We create a full tutorial of Angular CRUD with .NET Core API. I will show how to do it, and just follow […]
How to create new project in Angular
Angular is a TypeScript-based free and open-source web application framework led by the Angular Team at Google and by a community of individuals and corporations. […]