Angular PrimeNG Form InputGroup Addons Component
Last Updated :
28 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. In this article, we will learn how to use the InputGroup Addons Component in Angular PrimeNG.
The InputGroup component allows a user to input content.
Syntax:
<div class="p-inputgroup">
<span class="p-inputgroup-addon">
<i class="...."></i>
</span>
<input type="text" pInputText placeholder="....." />
</div>
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.
Steps to run the application: Run the below command to see the output:
ng serve --open
Example 1: Below is the example that illustrates the use of the Angular PrimeNG Form InputGroup Addons Component.
HTML
< h1 style = "color: green" >GeeksforGeeks</ h1 >
< h5 >Angular PrimeNG Form InputGroup Addons Component</ h5 >
< div class = "p-inputgroup" >
< span class = "p-inputgroup-addon" >
< i class = "pi pi-instagram" ></ i >
</ span >
< input type = "text" pInputText
placeholder = "Geeks Instagram username"
/>
</ div >
< br />
< div class = "p-inputgroup" >
< span class = "p-inputgroup-addon" >
< i class = "pi pi-twitter" ></ i >
</ span >
< input type = "text" pInputText
placeholder = "Geeks Twitter username"
/>
</ div >
|
Javascript
import { Component } from '@angular/core' ;
import { PrimeNGConfig } from 'primeng/api' ;
@Component({
selector: 'app-root' ,
templateUrl: './app.component.html'
})
export class AppComponent {
ngOnInit() {
this .primengConfig.ripple = true ;
}
constructor(private primengConfig: PrimeNGConfig) {}
}
|
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 {InputTextModule} from 'primeng/inputtext' ;
import {ButtonModule} from 'primeng/button' ;
import {CheckboxModule} from 'primeng/checkbox' ;
import {RadioButtonModule} from 'primeng/radiobutton' ;
import {RippleModule} from 'primeng/ripple' ;
@NgModule({
imports: [
BrowserModule,
BrowserAnimationsModule,
InputTextModule,
CheckboxModule,
ButtonModule,
RadioButtonModule,
RippleModule,
FormsModule
],
declarations: [ AppComponent ],
bootstrap: [ AppComponent ]
})
export class AppModule { }
|
Output:
Example 2: Below is another example that illustrates the use of the Angular PrimeNG Form InputGroup Addons Component.
HTML
< h1 style = "color: green" >GeeksforGeeks</ h1 >
< h5 >Angular PrimeNG Form InputGroup Addons Component</ h5 >
< div class = "p-inputgroup" >
< input type = "text" pInputText
placeholder = "Geeks LinkedIn username"
/>
< span class = "p-inputgroup-addon" >
< i class = "pi pi-linkedin" ></ i >
</ span >
</ div >
< br />
< div class = "p-inputgroup" >
< input type = "text" pInputText
placeholder = "Geeks Facebook username"
/>
< span class = "p-inputgroup-addon" >
< i class = "pi pi-facebook" ></ i >
</ span >
</ div >
|
Javascript
import { Component } from '@angular/core' ;
import { PrimeNGConfig } from 'primeng/api' ;
@Component({
selector: 'app-root' ,
templateUrl: './app.component.html'
})
export class AppComponent {
ngOnInit() {
this .primengConfig.ripple = true ;
}
constructor(private primengConfig: PrimeNGConfig) {}
}
|
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 {InputTextModule} from 'primeng/inputtext' ;
import {ButtonModule} from 'primeng/button' ;
import {CheckboxModule} from 'primeng/checkbox' ;
import {RadioButtonModule} from 'primeng/radiobutton' ;
import {RippleModule} from 'primeng/ripple' ;
@NgModule({
imports: [
BrowserModule,
BrowserAnimationsModule,
InputTextModule,
CheckboxModule,
ButtonModule,
RadioButtonModule,
RippleModule,
FormsModule
],
declarations: [ AppComponent ],
bootstrap: [ AppComponent ]
})
export class AppModule { }
|
Output:
Reference: https://primefaces.org/primeng/inputgroup
Share your thoughts in the comments
Please Login to comment...