import { Component, OnInit, Input, Output, EventEmitter, ElementRef, ContentChild, TemplateRef, HostBinding,forwardRef } from '@angular/core'; import { CfSelectableComponent } from '../selectable/selectable.component'; import { SelectableModel } from '../../models/selectable/selectable.model'; import { SwitchStylingModel } from '../../models/selectable/switch-styling.model'; import { SwitchTemplates } from '../../templates/switch.template'; /** *
Switch is creating using SelectableModel Class/Component based on Angular Material Slide toggle (Switch) and has abbility to customize md-slide-toggle's template.
. *Example of using Switch:
***/ @Component({ selector: 'cf-switch', template: "<cf-switch [settings]="myFruits" (cfOnChange)="log($event)"></cf-switch>*
The styling property of the checkbox.
*/ @Input() public styling: SwitchStylingModel; constructor(public elementRef: ElementRef) { super(elementRef); } /** * It will be generated cfCheckbox object and rendered inside component template. Also cfCheckStates function will initialize checkboxes states. */ ngOnInit() { this.activeTemplate = SwitchTemplates["defaultTemplate"]; if(this.compTemplate!=null && this.compTemplate!="") { if(SwitchTemplates[this.compTemplate]!=null) { this.activeTemplate = SwitchTemplates[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 SwitchStylingModel (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.checked; if(this.itemPosition!=null) this.properties.itemPosition = this.itemPosition; this.checked = this.properties.checked; this.cfSwitch = this.properties; } ngOnChanges(changes: any){ if(changes.disable!=null) this.properties.disable = changes.disable.currentValue; if(changes.display!=null) this.properties.display = changes.display.currentValue; if(changes.checkedValue!=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; } }