import { Component, OnInit, Input, Output, EventEmitter, ElementRef, ContentChild, TemplateRef, HostBinding } from '@angular/core'; import { FormsModule } from '@angular/forms'; import { CfSelectableComponent } from '../selectable/selectable.component'; import { SelectableModel } from '../../models/selectable/selectable.model'; import { RadioStylingModel } from '../../models/selectable/radio-styling.model'; import { RadioTemplates } from '../../templates/radio.template'; /** *
Radio is creating using SelectableModel Class/Component based on Angular Material Radio button and has abbility to customize md-radio-button's template.
. *Example of using Radio:
***/ @Component({ selector: 'cf-radio', template: "<cf-radio [settings]="myFruits" (cfOnChange)="log($event)"></cf-radio>*
The styling property of the radio.
*/ @Input() public styling: RadioStylingModel; constructor(public elementRef: ElementRef) { super(elementRef); } /** * It will be generated cfRadio object and rendered inside component template. Also cfCheckStates function will initialize checkboxes states. */ ngOnInit() { this.activeTemplate = RadioTemplates["defaultTemplate"]; if(this.compTemplate!=null && this.compTemplate!="") { if(RadioTemplates[this.compTemplate]!=null) { this.activeTemplate = RadioTemplates[this.compTemplate]; } else this.activeTemplate = this.compTemplate; } if(this.properties==null) { this.properties = new SelectableModel(this.activeTemplate["property"]); } else { var mainKeys = Object.keys(this.activeTemplate["property"]); for(let key of mainKeys) { if(this.properties[key]==null) this.properties[key]=this.activeTemplate["property"][key]; } } if(this.styling==null) this.styling = new RadioStylingModel (this.activeTemplate["style"]); if(this.disable!=null) this.properties.disable = this.disable; if(this.display!=null) this.properties.display = this.display; if(this.value!=null) this.properties.value = this.value; if(this.item!=null) this.properties.item = this.item; if(this.checked!=null) this.properties.checked = this.selected; if(this.itemPosition!=null) this.properties.itemPosition = this.itemPosition; this.cfRadio = this.properties; } ngOnChanges(changes: any){ if(this.properties!=null) { if(changes.disable!=null) this.properties.disable = changes.disable.currentValue; if(changes.display!=null) this.properties.display = changes.display.currentValue; if(changes.value!=null) this.properties.value = changes.value.currentValue; if(changes.item!=null) this.properties.item = changes.item.currentValue; if(changes.itemPosition!=null) this.properties.itemPosition = changes.itemPosition.currentValue; } } notifyGroup(){ this.selected = !this.selected; this.checked = this.selected; this.clicked.emit({"id":this.internalId, "value": this.selected}); } }