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

Переключатель

PrimeNG/InputSwitch (opens in a new tab)

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

С чего начать

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

import { InputSwitchModule } from 'primeng/inputswitch';

В .ts файле

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

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

<p-inputSwitch [(ngModel)]="checked1"></p-inputSwitch>

Basic

<p-inputSwitch [(ngModel)]="checked1"></p-inputSwitch>

Preselection

<p-inputSwitch [(ngModel)]="checked2"></p-inputSwitch>

Свойства

NameTypeDefaultDescription
stylestringnullInline style of the component.
styleClassstringnullStyle class of the component.
tabindexnumbernullIndex of the element in tabbing order.
inputIdstringnullIdentifier of the input element.
namestringnullName of the input element.
ariaLabelledBystringnullEstablishes relationships between the component and label(s) where its value should be one or more element IDs.
disabledbooleanfalseWhen present, it specifies that the element should be disabled.
readonlybooleanfalseWhen present, it specifies that the component cannot be edited.
trueValueanynullValue in checked state.
falseValueanynullValue in unchecked state.

События

NameParametersDescription
onChangeevent.originalEvent: browser event<br>event.checked: checked state as a booleanCallback to invoke on state change.

Стилизация

NameElement
p-inputswitchContainer element.
p-inputswitch-checkedContainer element in active state.
p-inputswitch-sliderSlider element behind the handle.