Компоненты PrimeNG
ToggleButton

Тумблер

PrimeNG/ToggleButton (opens in a new tab)

Тумблер используется для выбора логического значения с помощью кнопки.

С чего начать

Подключите модуль

import { ToggleButtonModule } from 'primeng/togglebutton';

В .ts файле

import { Component, OnInit } from '@angular/core';
 
@Component({
  selector: 'app-prime-togglebutton',
  templateUrl: './prime-togglebutton.component.html',
  styleUrls: ['./prime-togglebutton.component.scss']
})
export class PrimeTogglebuttonComponent implements OnInit {
 
  checked1: boolean = false;
  checked2: boolean = true;
 
  constructor() { }
 
  ngOnInit(): void {
  }
}

Встройте компонент с помощью тэга p-toggleButton.

<p-toggleButton [(ngModel)]="checked"></p-toggleButton>

Basic

<p-toggleButton [(ngModel)]="checked1" onIcon="pi pi-check" offIcon="pi pi-times"></p-toggleButton>

Customized

<p-toggleButton [(ngModel)]="checked2" onLabel="I confirm" offLabel="I reject" onIcon="pi pi-check" offIcon="pi pi-times" [style]="{'width': '10em'}"></p-toggleButton>

Свойства

NameTypeDefaultDescription
onLabelstringnullLabel for the on state.
offLabelstringnullLabel for the off state.
onIconstringnullIcon for the on state.
offIconstringnullIcon for the off state.
iconPosstringleftPosition of the icon, valid values are "left" and "right".
stylestringnullInline style of the element.
styleClassstringnullStyle class of the element.
disabledbooleanfalseWhen present, it specifies that the element should be disabled.
tabindexnumbernullIndex of the element in tabbing order.
inputIdstringnullIdentifier of the focus input to match a label defined for the component.
ariaLabelledBystringnullEstablishes relationships between the component and label(s) where its value should be one or more element IDs.

События

NameParametersDescription
onChangeevent.originalEvent: browser event<br>event.checked: boolean value to represent checked state.Callback to invoke on state change.

Стилизация

NameElement
p-togglebuttonContainer element
p-button-icon-leftIcon element.
p-button-icon-rightIcon element.
p-button-textLabel element.