Getting started with Angular Smart Paste Button component
28 Jul 20263 minutes to read
The Smart Paste Button is a user interface component designed to simplify and improve the experience of pasting text into form fields. It comes with smart features such as automatic text formatting, validation, and integration with various form controls. It is especially useful in applications where users frequently paste text from other sources and where data consistency is important.
This section explains how to create a simple Smart Paste Button and demonstrates its basic usage in an Angular environment.
Prerequisites
Dependencies
The list of dependencies required to use the SmartPasteButton module in your application is given below:
|-- @syncfusion/ej2-angular-buttons
|-- @syncfusion/ej2-angular-base
|-- @syncfusion/ej2-base
|-- @syncfusion/ej2-buttonsSetup Angular environment
You can use Angular CLI to set up your Angular applications. To install Angular CLI, use the following command.
npm install -g @angular/cli
Create an Angular application
Start a new Angular application using the following Angular CLI command.
ng new my-app
cd my-app
Installing Syncfusion® Button package
Syncfusion® packages are distributed in npm as @syncfusion scoped packages. You can get all the Angular Syncfusion® packages from npm link.
Currently, Syncfusion® provides two types of package structures for Angular components,
- Ivy library distribution package format
- Angular compatibility compiler (Angular’s legacy compilation and rendering pipeline) package.
Ivy library distribution package
Syncfusion® Angular packages (>=20.2.36) have been moved to the Ivy distribution to support the Angular Ivy rendering engine, and the packages are compatible with Angular version 12 and above. To download the package, use the following command.
Add @syncfusion/ej2-angular-buttons package to the application.
npm install @syncfusion/ej2-angular-buttons --saveAngular compatibility compiled package(ngcc)
For Angular version below 12, you can use the legacy (ngcc) package of the Syncfusion® Angular components. To download the ngcc package, use the following command.
Add @syncfusion/ej2-angular-buttons@ngcc package to the application.
npm install @syncfusion/ej2-angular-buttons@ngcc --saveTo mention the ngcc package in the package.json file, add the suffix -ngcc with the package version as below.
@syncfusion/ej2-angular-buttons:"27.1.50-ngcc"Note: If the ngcc tag is not specified while installing the package, the Ivy Library Package will be installed and this package will throw a warning.
Adding Syncfusion® Smart Paste Button component
Modify the template in the app.component.ts file to render the SmartPasteButtonModule module.
import { SmartPasteButtonModule } from '@syncfusion/ej2-angular-buttons'
import { Component } from '@angular/core';
@Component({
imports: [
SmartPasteButtonModule
],
standalone: true,
selector: 'app-root',
template: `<div class="e-section-control">
<!-- To render Smart Paste Button. -->
<button ejs-smart-paste-button>Smart Paste Button</button></div>`
})
export class AppComponent { }Adding CSS reference
Themes for Syncfusion® Angular components can be applied using CSS or SASS files from the npm theme packages, CDN, CRG, or Theme Studio. For more information, see the themes documentation.
This example uses the Tailwind 3 theme for the Smart Paste Button from the theme package. To install the Tailwind 3 theme package, use the following command:
npm install @syncfusion/ej2-tailwind3-theme --saveAdd Smart Paste Button component’s styles as given below in style.css.
@import "../node_modules/@syncfusion/ej2-tailwind3-theme/styles/button/index.css";Running the application
Run the application in the browser using the following command:
ng serve
The following is the output of the featured sample:
