/
githubmirror
/
tabby
Обзор
Документация
Войти
/
githubmirror
/
tabby
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
tabby-core/src/components/checkbox.component.ts
51 строка
1 KB
Eugene
bootstrap 5 WIP (#7891)
26 фев 2023, 22:42
Не верифицирован
26 фев 2023, 22:42
1e5cfd1
Код
Авторство
О чём код?
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */ import { NgZone, Component, Input, HostBinding, HostListener } from '@angular/core' import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms' /** @hidden */ @Component({ selector: 'checkbox', template: ` <div class="form-check form-checkbox"> <input type="checkbox" class="form-check-input" [(ngModel)]='model'> <label class="form-check-label">{{text}}</label> </div> `, providers: [ { provide: NG_VALUE_ACCESSOR, useExisting: CheckboxComponent, multi: true }, ], }) export class CheckboxComponent implements ControlValueAccessor { @HostBinding('class.active') @Input() model: boolean @HostBinding('class.disabled') @Input() disabled: boolean @Input() text: string private changed = new Array<(val: boolean) => void>() @HostListener('click') click () { NgZone.assertInAngularZone() if (this.disabled) { return } this.model = !this.model for (const fx of this.changed) { fx(this.model) } } writeValue (obj: any) { this.model = obj } registerOnChange (fn: any): void { this.changed.push(fn) } registerOnTouched (fn: any): void { this.changed.push(fn) } setDisabledState (isDisabled: boolean) { this.disabled = isDisabled } }