Angular PrimeNG Form InputMask SlotChar Component
Last Updated :
17 Oct, 2022
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 the Form InputMask SlotChar Component in Angular PrimeNG. We will also learn about the various properties and syntaxes used in the code example.
The InputMask component allows users to input values in a certain format which includes numeric, date, currency, and phone.
Angular PrimeNG Form InputMask SlotChar Component properties:
- mask: It defines the pattern of the mask.
- slotChar: It is a mask’s placeholder character, & the default value is an underscore.
Syntax:
<p-inputMask
mask="..."
slotChar="...">
</p-inputMask>
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.
To run the above file, run the below command:
ng serve --save
Example 1: Below is the example that illustrates the use of Angular PrimeNG Form InputMask SlotChar Component using slotChar=”99-a*-a999″.
HTML
< h2 style = "color: green" >GeeksforGeeks</ h2 >
< h5 >PrimeNG InputMask SlotChar component</ h5 >
< p-inputMask
mask = "99-a*-a999"
slotChar = "99-a*-a999" >
</ p-inputMask >
|
Javascript
import { Component } from '@angular/core' ;
@Component({
selector: 'app-root' ,
templateUrl: './app.component.html' ,
})
export class AppComponent { }
|
Javascript
import { NgModule } from '@angular/core' ;
import { BrowserModule } from '@angular/platform-browser' ;
import { FormsModule } from '@angular/forms' ;
import { BrowserAnimationsModule }
from '@angular/platform-browser/animations' ;
import { AppComponent } from './app.component' ;
import { InputMaskModule } from 'primeng/inputmask' ;
@NgModule({
imports: [
BrowserModule,
BrowserAnimationsModule,
InputMaskModule,
FormsModule
],
declarations: [AppComponent],
bootstrap: [AppComponent]
})
export class AppModule { }
|
Output:
Example 2: Below is another example that illustrates the use of Angular PrimeNG Form InputMask SlotChar Component using slotChar=”*9-aaaaaaaaaaaaa”.
HTML
< h2 style = "color: green" >GeeksforGeeks</ h2 >
< h5 >PrimeNG InputMask SlotChar component</ h5 >
< p-inputMask
mask = "*9-aaaaaaaaaaaaa"
slotChar = "*9-aaaaaaaaaaaaa" >
</ p-inputMask >
|
Javascript
import { Component } from '@angular/core' ;
@Component({
selector: 'app-root' ,
templateUrl: './app.component.html' ,
})
export class AppComponent { }
|
Javascript
import { NgModule } from '@angular/core' ;
import { BrowserModule } from '@angular/platform-browser' ;
import { FormsModule } from '@angular/forms' ;
import { BrowserAnimationsModule }
from '@angular/platform-browser/animations' ;
import { AppComponent } from './app.component' ;
import { InputMaskModule } from 'primeng/inputmask' ;
@NgModule({
imports: [
BrowserModule,
BrowserAnimationsModule,
InputMaskModule,
FormsModule
],
declarations: [AppComponent],
bootstrap: [AppComponent]
})
export class AppModule { }
|
Output:
Reference: https://primefaces.org/primeng/inputmask
Share your thoughts in the comments
Please Login to comment...