InputtextInputText is an extension to standard input element with theming.

InputText - 图1

Documentation

Import

  1. import {InputTextModule} from 'primeng/inputtext';
  2.  

Getting Started

InputText is applied to an input field with pInputText directive.

  1. <input type="text" pInputText />
  2.  

Model Binding

A model can be bound using standard ngModel directive.

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

Addons

Text, icon, buttons and other content can be grouped next to an input by wrapping the addons and input inside .ui-inputgroup element. Multiple addons can be used within the same group as well.

  1. <div class="ui-inputgroup">
  2. <span class="ui-inputgroup-addon"><i class="fa fa-user"></i></span>
  3. <input type="text" pInputText placeholder="Username">
  4. </div>
  5. <div class="ui-inputgroup">
  6. <span class="ui-inputgroup-addon"><i class="fa fa-credit-card"></i></span>
  7. <span class="ui-inputgroup-addon"><i class="fa fa-cc-visa"></i></span>
  8. <input type="text" pInputText placeholder="Price">
  9. <span class="ui-inputgroup-addon">$</span>
  10. <span class="ui-inputgroup-addon">.00</span>
  11. </div>
  12.  

Float Label

A floating label is implemented by wrapping the input and the label inside a container with .ui-float-label class.

  1. <span class="ui-float-label">
  2. <input id="float-input" type="text" size="30" pInputText>
  3. <label for="float-input">Username</label>
  4. </span>
  5.  

Properties

NameTypeDefaultDescription
disabledbooleanfalseWhen present, it specifies that the element should be disabled.

Styling

Following is the list of structural style classes, for theming classes visit theming page.

NameElement
ui-inputtextInput element

Dependencies

None.

Source

View on GitHub

  1. <h3 class="first">Basic</h3>
  2. <input id="input" type="text" size="30" pInputText [(ngModel)]="text">
  3. <span id="text">{{text}}</span>
  4. <h3>Float Label</h3>
  5. <span class="ui-float-label">
  6. <input id="float-input" type="text" size="30" pInputText>
  7. <label for="float-input">Username</label>
  8. </span>
  9. <h3>Disabled</h3>
  10. <input id="disabled-input" type="text" size="30" pInputText [disabled]="disabled" />
  11. <button id="disabled-btn" type="button" (click)="toggleDisabled()" pButton label="Toggle"></button>
  12.  
  1. export class InputTextDemo {
  2. text: string;
  3. disabled: boolean = true;
  4. toggleDisabled() {
  5. this.disabled = !this.disabled;
  6. }
  7. }
  8.