Open In App

Angular PrimeNG InputNumber Component

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. In this article, we will know how to use the InputNumber component in Angular PrimeNG. We will also learn about the properties, events, methods & styling along with their syntaxes that will be used in the code. 

InputNumber component: It allows a user to input content as a numerical value.



Properties:

Methods:



 

Events:

Styling:

Creating Angular application & module installation:

ng new appname
cd appname
npm install primeng --save
npm install primeicons --save

Project Structure: It will look like the following:

Example 1: This is the basic example that illustrates how to use the InputNumber component. 




<h2>GeeksforGeeks</h2>
<h5>PrimeNG inputNumber component</h5>
<div class="p-grid p-fluid">
  <div class="p-field p-col-12 p-md-3">
    <p-inputNumber placeholder="Input number here">
    </p-inputNumber>
  </div>
</div>

 




import { NgModule } from "@angular/core";
import { BrowserModule } from "@angular/platform-browser";
import { AppComponent } from "./app.component";
  
import { InputNumberModule } from "primeng/inputnumber";
  
@NgModule({
  imports: [BrowserModule, InputNumberModule],
  declarations: [AppComponent],
  bootstrap: [AppComponent],
})
export class AppModule {}




import { Component } from "@angular/core";
  
@Component({
  selector: "my-app",
  templateUrl: "./app.component.html",
})
export class AppComponent {}

Output:

Example 2: In this example, we will know how to use prefix & suffix property in the InputNumber component.




<h2>GeeksforGeeks</h2>
<h5>PrimeNG inputNumber component</h5>
<div class="p-field p-col-12 p-md-3">
  <label for="gfg">Prefix and Suffix Property</label>
  <p-inputNumber inputId="gfg" suffix=")" 
                 prefix="(" placeholder="()">
  </p-inputNumber>
</div>




import { NgModule } from "@angular/core";
import { BrowserModule } from "@angular/platform-browser";
import { AppComponent } from "./app.component";
  
import { InputNumberModule } from "primeng/inputnumber";
  
@NgModule({
  imports: [BrowserModule, InputNumberModule],
  declarations: [AppComponent],
  bootstrap: [AppComponent],
})
export class AppModule {}




import { Component } from "@angular/core";
  
@Component({
  selector: "my-app",
  templateUrl: "./app.component.html",
})
export class AppComponent {}

Output:

Reference: https://primeng.org/inputnumber


Article Tags :