SpinnerSpinner is an input component to provide a numerical input.

Spinner - 图1

Documentation

Import

  1. import {SpinnerModule} from 'primeng/spinner';
  2.  

Getting Started

Two-way value binding is defined using standard ngModel directive.

  1. <p-spinner size="30" [(ngModel)]="val"></p-spinner>
  2.  

Model Driven Forms

Spinner can be used in a model driven form as well.

  1. <p-spinner formControlName="age"></p-spinner>
  2.  

Min-Max

Boundaries are specified with min and max attributes.

  1. <p-spinner size="30" [(ngModel)]="val" [min]="0" [max]="100"></p-spinner>
  2.  

Step

Step factor is 1 by default and can be customized with step option.

  1. <p-spinner size="30" [(ngModel)]="val" [step]="0.25"></p-spinner>
  2.  

Properties

NameTypeDefaultDescription
stepnumber1Step factor to increment/decrement the value.
minnumbernullMininum boundary value.
maxnumbernullMaximum boundary value.
placeholderstringnullHint text for the input field.
disabledbooleanundefinedWhen present, it specifies that the element should be disabled.
readonlybooleanundefinedWhen present, it specifies that the element should be read-only.
maxlengthnumbernullMaximum number of character allows in the input field.
sizenumbernullSize of the input field.
tabindexnumbernullIndex of the element in tabbing order.
inputIdstringnullIdentifier of the focus input to match a label defined for the component.
typestringtextType of the input field.
requiredbooleanfalseWhen present, it specifies that an input field must be filled out before submitting the form.
namestringnullName of the input field.
inputStylestringnullInline style of the input field.
inputStyleClassstringnullStyle class of the input field.

Events

NameParametersDescription
onBlurevent: Blur eventCallback to invoke when input loses focus.
onFocusevent: Browser eventCallback to invoke when input gets focus.
onChangeevent: Change eventCallback to invoke on value change.

Styling

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

NameElement
ui-spinnerContainer element
ui-spinner-upUp element
ui-spinner-downDown button

Dependencies

None.

Source

View on GitHub

  1. <h3 class="first">Basic</h3>
  2. <p-spinner size="30" [(ngModel)]="val1"></p-spinner>
  3. <h3>Min/Max</h3>
  4. <p-spinner size="30" [(ngModel)]="val2" [min]="0" [max]="100"></p-spinner>
  5. <h3>Step</h3>
  6. <p-spinner size="30" [(ngModel)]="val3" [step]="0.25"></p-spinner>
  7. <h3>Disabled</h3>
  8. <p-spinner size="30" [(ngModel)]="val4" [disabled]="true"></p-spinner>
  9.  
  1. export class SpinnerDemo {
  2. val1: number;
  3. val2: number;
  4. val3: number;
  5. val4: number = 100;
  6. }
  7.