Articles in this section
Category / Section

How to render Uploader in Angular 7 Material Uploader?

7 mins read

A quick start project that helps you to create an Angular 7 Material Uploader component with a minimal code configuration.

Angular 7 Material Uploader

The following section explains the steps required to create a simple Angular 7 Material Uploader component.

Prerequisites

Make sure that you have the compatible versions of Angular in your machine before starting to work on this project.

Introduction

The Angular 7 Material Uploader used in this project is created from the Syncfusion ej2-angular-inputs package. You can simply define it as <ejs-uploader> within the template.

Dependencies

Before starting with this project, the Angular 7 Material Uploader requires to add the Syncfusion ej2-angular-inputs package from npmjs, which are distributed in npm as @syncfusion scoped packages. Uploader requires the following dependent packages for rendering Uploader component.

 

|-- @syncfusion/ej2-angular-inputs
    |-- @syncfusion/ej2-angular-base
    |-- @syncfusion/ej2-angular-popups
    |-- @syncfusion/ej2-angular-buttons
    |-- @syncfusion/ej2-inputs
        |-- @syncfusion/ej2-base
        |-- @syncfusion/ej2-popups
        |-- @syncfusion/ej2-buttons

 

The following CSS styles require dependencies to render the Uploader component.

 

@import '../node_modules/@syncfusion/ej2-base/styles/material.css';
@import '../node_modules/@syncfusion/ej2-buttons/styles/material.css';
@import '../node_modules/@syncfusion/ej2-inputs/styles/material.css';
@import '../node_modules/@syncfusion/ej2-popups/styles/material.css';
@import '../node_modules/@syncfusion/ej2-angular-inputs/styles/material.css'; 

 

Creating Angular Project

To create the Angular project using the Angular CLI tool, follow the given steps. Install Angular CLI 7 using following command.

 

npm install @angular/cli@7.0.4

 

Now, create a new Angular project by using the command ng new and navigate to that folder.

 

ng new <project name>
cd <project name>

 

Install the ej2-angular-inputs package through the npm install command.

 

npm install @syncfusion/ej2-angular-inputs --save

 

Adding Angular 7 Material Uploader

 

You can add the Angular 7 Uploader component by using the ejs-uploader directive and the attributes within the tag allows you to define other functionalities. Import the Uploader module into the Angular application (app.module.ts) from the ej2-angular-inputs package.

 

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { UploaderModule } from '@syncfusion/ej2-angular-inputs’;
import { AppCompnent } from './app.component';
 
@NgModule({ 
    imports: [ BrowserModule, UploaderModule],
    declarations: [ AppComponent ],
    bootstrap: [ AppComponent ]
})
 
export class AppModule {}

 

Define the Angular Uploader code within the app.component.html file mapped against the templateUrl option in app.component.ts file.

Here, the Uploader component is rendered with the asyncSettings property.

[app.component.ts]

import { Component } from '@angular/core';
 
@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
  public path: Object = {
    saveUrl: 'https://aspnetmvc.syncfusion.com/services/api/uploadbox/Save',
    removeUrl: 'https://aspnetmvc.syncfusion.com/services/api/uploadbox/Remove'
  };
}

 

[app.component.html]

 <ejs-uploader [asyncSettings]='path'></ejs-uploader>

 

Refer to the CDN link of CSS reference within the styles.css file.

@import '../node_modules/@syncfusion/ej2-base/styles/material.css';
@import '../node_modules/@syncfusion/ej2-buttons/styles/material.css';
@import '../node_modules/@syncfusion/ej2-inputs/styles/material.css';
@import '../node_modules/@syncfusion/ej2-popups/styles/material.css';
@import '../node_modules/@syncfusion/ej2-angular-inputs/styles/material.css';

 

Run the application with the command ng serve and an Uploader with material theme will be displayed on the browser as follows.

Syncfusion Angular Uploader

 

Also, you can download and run the sample in this GitHub Repository. For more information about Uploader functionalities, refer to UG Documentation,  API Reference, and Samples section.

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied