File

projects/commons/src/lib/elements/check-radio/components/check-radio.component.ts

Extends

Field

Implements

OnInit

Metadata

selector cmn-check-radio
styleUrls ./check-radio.component.scss
templateUrl ./check-radio.component.html

Index

Properties
Methods
Inputs

Constructor

constructor(viewRef: ViewContainerRef)
Parameters :
Name Type Optional
viewRef ViewContainerRef No

Inputs

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'

Methods

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 :
Name Type Optional Default value
name string No
validators Validators No
value string No ''
Returns : void
Public ngOnInit
ngOnInit()
Inherited from Field
Defined in Field:9
Returns : void

Properties

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

Legend
Html element
Component
Html element with directive

result-matching ""

    No results matching ""