Open In App

Angular PrimeNG FileUpload Basic UI

Last Updated : 28 Oct, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

Angular PrimeNG is an open-source framework with a rich set of native Angular UI components that are used for great styling and this framework is used to make responsive websites with very much ease. This article will show us how to use FileUpload Basic UI in Angular PrimeNG.

Angular PrimeNG FileUpload Basic UI Mode provides a simpler UI as an alternative to advanced mode.

Syntax:

<p-fileUpload mode="basic" 
              name="..." 
              url="..." 
              chooseLabel="...">
</p-fileUpload>

 

Creating Angular application & Module Installation:

Step 1: Create an Angular application using the following command.

ng new appname

Step 2: After creating your project folder i.e. appname, move to it using the following command.

cd appname

Step 3: Install PrimeNG in your given directory.

npm install primeng --save
npm install primeicons --save

Project Structure: It will look like the following:

 

Example 1: Below is a simple example demonstrating the use of the Angular PrimeNG FileUpload Basic UI.

  • app.component.html

HTML




<h2 style="color: green">
    GeeksforGeeks
</h2>
<h4>
    Angular PrimeNG FileUpload Basic UI
</h4>
  
<p-fileUpload mode="basic" 
              name="demo[]" 
              url="./upload.php" 
              accept="image/*" 
              maxFileSize="1000000">
</p-fileUpload>


  • app.component.ts

Javascript




import { Component, OnInit } from '@angular/core';
  
@Component({
    selector: 'app-root',
    templateUrl: './app.component.html',
    providers: [],
})
export class AppComponent {
    constructor() { }
    ngOnInit() { }
}


  • app.module.ts

Javascript




import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { RouterModule } from '@angular/router';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { FileUploadModule } from 'primeng/fileupload';
import { AppComponent } from './app.component';
import { HttpClientModule } from '@angular/common/http';
import { ButtonModule } from 'primeng/button';
  
@NgModule({
    imports: [
        BrowserModule,
        BrowserAnimationsModule,
        ButtonModule,
        HttpClientModule,
        FileUploadModule,
        RouterModule.forRoot([{ path: '', component: AppComponent }]),
    ],
    declarations: [AppComponent],
    bootstrap: [AppComponent],
})
export class AppModule { }


Output:

 

Example 2: Below is another example demonstrating the use of the Angular PrimeNG FileUpload Basic UI. In this example, we are using Basic UI FileUpload with chooselabel and auto upload.

  • app.component.html

HTML




<h2 style="color: green">
    GeeksforGeeks
</h2>
<h4>
    Angular PrimeNG FileUpload Basic UI
</h4>
  
<p-fileUpload
    mode="basic"
    name="demo[]"
    url="./upload.php"
    accept="image/*"
    maxFileSize="1000000"
    chooseLabel="Browse Files"
    [auto]="true"
></p-fileUpload>


  • app.component.ts

Javascript




import { Component, OnInit } from '@angular/core';
  
@Component({
    selector: 'app-root',
    templateUrl: './app.component.html',
    providers: [],
})
export class AppComponent {
    constructor() { }
    ngOnInit() { }
}


  • app.module.ts

Javascript




import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { RouterModule } from '@angular/router';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { FileUploadModule } from 'primeng/fileupload';
import { AppComponent } from './app.component';
import { HttpClientModule } from '@angular/common/http';
import { ButtonModule } from 'primeng/button';
  
@NgModule({
    imports: [
        BrowserModule,
        BrowserAnimationsModule,
        ButtonModule,
        HttpClientModule,
        FileUploadModule,
        RouterModule.forRoot([{ path: '', component: AppComponent }]),
    ],
    declarations: [AppComponent],
    bootstrap: [AppComponent],
})
export class AppModule { }


Output:

 

Reference: https://primefaces.org/primeng/fileupload



Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads