Angular PrimeNG Form Inputtext Model Binding
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 & syntaxes that will be used in the code.
The InputTextArea component is an element that is used to make a text field with multi-line input support.
Model Binding: ngModel directive is used to bind the model.
Syntax:
<input type="text" pInputText [(ngModel)]="property" />
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.

Step to run the application: Run the below command to see the output
ng serve --save
Example 1: In the below code, we will make use of the above syntax to demonstrate the use of the Form Inputtext Model Binding Component.
- app.component.html:
HTML
< div style = "text-align:center" > < h1 style = "color:green" >GeeksforGeeks</ h1 > < h3 >Angular PrimeNG Form Inputtext Model Binding Component</ h3 > < input type = "text" pInputText [(ngModel)]="property" /> </ div > |
- app.component.ts:
Javascript
import { Component } from '@angular/core' ; import { MenuItem } from 'primeng/api' ; @Component({ selector: 'app-root' , templateUrl: './app.component.html' , styleUrls: [ './app.component.scss' ], }) export class AppComponent { disabled: boolean = true ; value1: string; value2: string; value3: string; value4: string; value5: string = 'Disabled' ; } |
- app.module.ts:
Javascript
import { NgModule } from '@angular/core' ; import { BrowserModule } from '@angular/platform-browser' ; import { FormsModule } from '@angular/forms' ; import { HttpClientModule } from '@angular/common/http' ; import { BrowserAnimationsModule } from '@angular/platform-browser/animations' ; import { AppComponent } from './app.component' ; import { InputTextModule } from 'primeng/inputtext' ; import { ButtonModule } from 'primeng/button' ; @NgModule({ imports: [ BrowserModule, BrowserAnimationsModule, InputTextModule, ButtonModule, FormsModule, ], declarations: [AppComponent], bootstrap: [AppComponent], }) export class AppModule { } |
Output:
.gif)
Example 2: In the below code, we will make use of the above syntax to demonstrate the use of the Form Inputtext Model Binding Component.
- app.component.html:
HTML
< div style = "text-align:center" > < h2 style = "color:green" >GeeksforGeeks</ h2 > < h3 >PrimeNG InputText component</ h3 > < div class = "sizes" > < input type = "text" class = "p-inputtext-sm" placeholder = "Input text here" [(ngModel)]="property" pInputText /> < input type = "text" placeholder = "Input text here" [(ngModel)]="property" pInputText /> < input type = "text" class = "p-inputtext-lg" placeholder = "Input text here" [(ngModel)]="property" pInputText /> </ div > </ div > |
- app.component.ts:
Javascript
import { Component } from '@angular/core' ; import {MenuItem} from 'primeng/api' ; @Component({ selector: 'app-root' , templateUrl: './app.component.html' , styleUrls: [ './app.component.scss' ] }) export class AppComponent { disabled: boolean = true ; value1: string; value2: string; value3: string; value4: string; value5: string = 'Disabled' ; } |
- app.module.ts:
Javascript
import { NgModule } from '@angular/core' ; import { BrowserModule } from '@angular/platform-browser' ; import {FormsModule} from '@angular/forms' ; import { HttpClientModule } from '@angular/common/http' ; import { BrowserAnimationsModule } from '@angular/platform-browser/animations' ; import { AppComponent } from './app.component' ; import {InputTextModule} from 'primeng/inputtext' ; import {ButtonModule} from 'primeng/button' ; @NgModule({ imports: [ BrowserModule, BrowserAnimationsModule, InputTextModule, ButtonModule, FormsModule ], declarations: [ AppComponent ], bootstrap: [ AppComponent ] }) export class AppModule { } |
Output:
.gif)
Reference: https://primefaces.org/primeng/inputtext
Please Login to comment...