Open In App

Angular PrimeNG InputText Component

Last Updated : 14 Feb, 2023
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. In this article, we will know how to use the InputText component in angular primeNG. Let’s learn about the properties, styling & their syntaxes that will be used in the code. 

InputTextArea component: It is an element that is used to make a text field with multi-line input support.

Properties:

  • disabled: We can set the input component to be disabled. It is of a boolean data type & the default value is false.

Styling:

  • p-inputtext: It is a directive & applied to the text input field.
<input type="text" pInputText />

 

Model Binding: ngModel directive is used to bind the model.

<input type="text" pInputText [(ngModel)]="property"/>

Size: In addition to the regular sizes, there are more than 2 sizes that are available, add p-inputtext-sm for small text input & add p-inputtext-lg for large text input. These classes must be used to change the size of the particular input field.
For smaller input text

<input type="text" pInputText class="p-inputtext-sm">

For larger input text

<input type="text" pInputText class="p-inputtext-lg"> 

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: This is the basic example that shows how to use InputText component 

app.component.html




<h2>GeeksforGeeks</h2>
<h5>PrimeNG InputText component</h5>
<div class="sizes">
  <input
    type="text"
    class="p-inputtext-lg"
    placeholder="Input text here"
    pInputText/>
</div>


app.module.ts




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


Output:

Example 2: In this example, we will know how to set the size of the InputText component. 

app.component.html




<h2>GeeksforGeeks</h2>
<h5>PrimeNG InputText component</h5>
<div class="sizes">
  <input
    type="text"
    class="p-inputtext-sm"
    placeholder="Input text here"
    pInputText/>
  <input type="text" placeholder="Input text here" pInputText />
  <input
    type="text"
    class="p-inputtext-lg"
    placeholder="Input text here"
    pInputText/>
</div>


app.module.ts




import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { BrowserAnimationsModule } 
    from '@angular/platform-browser/animations';
  
import { AppComponent } from './app.component';
  
import { InputTextModule } from 'primeng/inputtext';
  
@NgModule({
  imports: [BrowserModule, 
              BrowserAnimationsModule, 
            InputTextModule],
  declarations: [AppComponent],
  bootstrap: [AppComponent]
})
export class AppModule {}


Output:

Reference: http://primefaces.org/primeng/inputtext



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

Similar Reads