projects/commons/src/lib/elements/check-radio/components/check-radio.component.ts
| selector | cmn-check-radio |
| styleUrls | ./check-radio.component.scss |
| templateUrl | ./check-radio.component.html |
Properties |
|
Methods |
|
Inputs |
constructor(viewRef: ViewContainerRef)
|
||||||
|
Parameters :
|
| class | |
Type : string
|
|
| id | |
Type : string
|
|
| isDisabled | |
Type : boolean
|
|
| isRtl | |
Type : boolean
|
|
| label | |
Type : string
|
|
| name | |
Type : string
|
|
| type | |
Type : "radio" | "checkbox"
|
|
Default value : 'checkbox'
|
|
| Public ngOnInit |
ngOnInit()
|
|
Returns :
void
|
| Public onChange |
onChange()
|
|
Returns :
void
|
| Protected addFormValidator | ||||||||||||||||
addFormValidator(name: string, validators: Validators, value: string)
|
||||||||||||||||
|
Inherited from
Field
|
||||||||||||||||
|
Defined in
Field:17
|
||||||||||||||||
|
Parameters :
Returns :
void
|
| Public ngOnInit |
ngOnInit()
|
|
Inherited from
Field
|
|
Defined in
Field:9
|
|
Returns :
void
|
| Public form |
Type : FormGroup
|
|
Inherited from
Field
|
|
Defined in
Field:5
|
import { Component, Input, OnInit, ViewContainerRef } from '@angular/core';
import { Field } from '../../../core/field/abstract';
@Component({
selector: 'cmn-check-radio',
templateUrl: './check-radio.component.html',
styleUrls: [ './check-radio.component.scss' ],
})
export class CheckRadioComponent extends Field implements OnInit {
@Input() public readonly id: string;
@Input() public readonly name: string;
@Input() public readonly label: string;
@Input() public readonly isRtl: boolean;
@Input() public readonly isDisabled: boolean;
@Input('class') public readonly clazz: string;
@Input() public readonly type: 'radio' | 'checkbox' = 'checkbox';
constructor(private readonly viewRef: ViewContainerRef) {
super(viewRef);
}
public ngOnInit(): void {
super.ngOnInit();
this.addFormValidator(this.name, []);
}
public onChange(): void {
this.form.get(this.name).setValue(!this.form.get(this.name).value);
}
}
<div [formGroup]="form">
<input class="is-checkradio {{ clazz }}"
[formControlName]="name"
[class.is-rtl]="isRtl"
[id]="id"
[type]="type"
[value]="form.get(this.name).value"
[disabled]="isDisabled"/>
<label [for]="id"
(click)="onChange()">
{{ label }}
</label>
<small>
<ng-content></ng-content>
</small>
</div>
./check-radio.component.scss