import {Renderer, ElementRef, EventEmitter} from 'angular2/angular2' import {Component, Directive, onInit} from 'angular2/src/core/annotations_impl/annotations'; import {Ancestor} from 'angular2/src/core/annotations_impl/visibility'; import {View} from 'angular2/src/core/annotations_impl/view'; import {Control, NgControl,NgFormControl} from 'angular2/forms'; import {ControlGroup, ControlDirective} from 'angular2/forms' import {dom} from 'ionic/util'; import {IonicComponent} from 'ionic/config/component' @Directive({ selector: 'ion-segment', host: { '(change)': 'onChange($event.target.value)', '(input)': 'onChange($event.target.value)', '(blur)': 'onTouched()', '[value]': 'value', '[class.ng-untouched]': 'cd.control?.untouched == true', '[class.ng-touched]': 'cd.control?.touched == true', '[class.ng-pristine]': 'cd.control?.pristine == true', '[class.ng-dirty]': 'cd.control?.dirty == true', '[class.ng-valid]': 'cd.control?.valid == true', '[class.ng-invalid]': 'cd.control?.valid == false' } }) export class SegmentControlValueAccessor { constructor(cd: NgControl, renderer: Renderer, elementRef: ElementRef) { console.log('CoONSTRUCTING VALUE ACCESSOR', cd); this.onChange = (_) => {}; this.onTouched = (_) => {}; this.cd = cd; this.renderer = renderer; this.elementRef = elementRef; cd.valueAccessor = this; } writeValue(value) { // both this.value and setProperty are required at the moment // remove when a proper imperative API is provided console.log('WRITE VALUE', value); this.value = !value ? '' : value; this.renderer.setElementProperty(this.elementRef.parentView.render, this.elementRef.boundElementIndex, 'value', this.value); } registerOnChange(fn) { console.log('REGISTER ON CHANGE'); this.onChange = fn; } registerOnTouched(fn) { this.onTouched = fn; } } @Component({ selector: 'ion-segment', appInjector: [ NgFormControl ], properties: [ 'value' ], host: { '(click)': 'buttonClicked($event)', '(change)': 'onChange($event)', '[value]': 'value', '[class.ng-untouched]': 'cd.control?.untouched == true', '[class.ng-touched]': 'cd.control?.touched == true', '[class.ng-pristine]': 'cd.control?.pristine == true', '[class.ng-dirty]': 'cd.control?.dirty == true', '[class.ng-valid]': 'cd.control?.valid == true', '[class.ng-invalid]': 'cd.control?.valid == false' } }) @View({ template: `