import { Component , TemplateRef , Input , ContentChild , ChangeDetectionStrategy , ChangeDetectorRef , HostBinding , OnInit , AfterContentInit , OnDestroy } from '@angular/core' ; import { Subscription } from 'rxjs' ; import { NglRadioGroup } from './radio-group' ; import { NglRadioInput } from './input/input' ; @ Component ( { selector : 'ngl-radio-option' , templateUrl : './radio-option.html' , changeDetection : ChangeDetectionStrategy . OnPush , } ) export class NglRadioOption implements OnInit , AfterContentInit , OnDestroy { @ Input ( ) label : string | TemplateRef < any > ; @ ContentChild ( NglRadioInput , { static : true } ) input : NglRadioInput ; constructor ( private radioGroup , private cd ) { } type : 'list' | 'button' ; @ HostBinding ( 'class.slds-radio' ) get isTypeList ( ) { return this . type === 'list' ; } @ HostBinding ( 'class.slds-button' ) @ HostBinding ( 'class.slds-radio_button' ) get isTypeButton ( ) { return this . type === 'button' ; } private subscriptions : Subscription [ ] = [ ] ; ngOnInit ( ) { this . subscriptions . push ( this . radioGroup . type$ . subscribe ( ( type ) => { this . type = type ; this . cd . detectChanges ( ) ; } ) , this . radioGroup . error$ . subscribe ( ( errorId ) => { this . input . describedBy = errorId ; } ) ) ; } ngAfterContentInit ( ) { this . input . name = this . radioGroup . uid ; } ngOnDestroy ( ) { this . subscriptions . forEach ( ( s ) => s . unsubscribe ( ) ) ; } }