
Security News
npm Adopts OIDC for Trusted Publishing in CI/CD Workflows
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.
ng-files-input
Advanced tools
Angular file input component with built-in preview and optional upload support with progress tracking.
ng-files-input is an Angular library for previewing uploaded files with support for images, PDFs, plain text, and more — all wrapped in a highly customizable and developer-friendly file input component.
ngModel
and FormControl
npm install ng-files-input
import { NgFilesInput, UploadType } from "ng-files-input";
@Component({
imports: [NgFilesInput],
})
export class ExampleComponent {
uploadType = UploadType.IMAGE;
}
<ng-files-input [uploadType]="uploadType" [accept]="'.png,.jpg'" [(ngModel)]="file" [disabled]="false" [showPreview]="true"> Please select image </ng-files-input>
--ng-files-area-width: 200px;
--ng-files-area-height: 180px;
--ng-files-border-width: 2px;
--ng-files-border-style: solid;
--ng-files-border-color: #9e9e9e;
--ng-files-background: #f5f5f5;
--ng-files-icon-size: 40;
--ng-files-icon-color: green; // This may or may not work
--ng-files-placeholder-color: #292826;
--ng-files-placeholder-font-size: 12px;
--ng-files-placeholder-gap: 5px;
--ng-files-progress-bar-color: green;
TS
import { HttpClient, HttpRequest } from "@angular/common/http";
import { Component, inject } from "@angular/core";
@Component({
selector: "app-file-upload",
templateUrl: "./file-upload.component.html",
})
export class FileUploadComponent {
private http = inject(HttpClient);
// Upload function passed to ng-files-input
uploadFile = (file: File) => {
const formData = new FormData();
formData.append("file", file);
const req = new HttpRequest("POST", "https://your.api/upload", formData, {
reportProgress: true, // enables progress events
});
return this.http.request(req); // returns Observable<HttpEvent<any>>
};
}
HTML
<ng-files-input [(ngModel)]="selectedFile" [uploadFn]="uploadFile"></ng-files-input>
uploadFn(file)
HttpEventType.UploadProgress
(uploadProgress)
or (uploadComplete)
outputs)Internally, your component might do something like:
uploadFn(file).subscribe((event) => {
if (event.type === HttpEventType.UploadProgress) {
const percent = Math.round((100 * event.loaded) / (event.total ?? 1));
this.progress = percent;
} else if (event.type === HttpEventType.Response) {
this.uploadComplete.emit(event.body);
}
});
File Type | Preview Method |
---|---|
Images (.png , .jpg , etc.) | <img> tag |
PDFs | <iframe> or <embed> |
Text files | <pre> element |
Others | ⚠️ Fallback message displayed |
Input | Type | Description |
---|---|---|
accept | string | Accepted MIME types or extensions |
disabled | boolean | Disable file input |
ngModel / formControl | Base64 | null |
MIT
Made with ❤️ by Sanjib Kumar Mandal
FAQs
Angular file input component with built-in preview and optional upload support with progress tracking.
The npm package ng-files-input receives a total of 4 weekly downloads. As such, ng-files-input popularity was classified as not popular.
We found that ng-files-input demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.
Research
/Security News
A RubyGems malware campaign used 60 malicious packages posing as automation tools to steal credentials from social media and marketing tool users.
Security News
The CNA Scorecard ranks CVE issuers by data completeness, revealing major gaps in patch info and software identifiers across thousands of vulnerabilities.