diff --git a/ionic/components/segment/segment.js b/ionic/components/segment/segment.js index 5b4c8b6949..c3556a1456 100644 --- a/ionic/components/segment/segment.js +++ b/ionic/components/segment/segment.js @@ -1,4 +1,5 @@ import {NgElement, Renderer, ElementRef, Component, DefaultValueAccessor, View, Ancestor, Optional, Decorator, Directive} from 'angular2/angular2' +import {ControlGroup, ControlDirective} from 'angular2/forms' import {dom} from 'ionic/util'; import {IonicComponent} from 'ionic/config/component' import {Button} from 'ionic/components/button/button' @@ -15,22 +16,37 @@ import {Button} from 'ionic/components/button/button' `, - directives: [Button, SegmentButton] + directives: [Button, SegmentButton], + properties: { + value: 'value' + }, + hostProperties: { + value: 'value' + } }) export class Segment { constructor( @NgElement() ngElement:NgElement, elementRef: ElementRef, - renderer: Renderer + renderer: Renderer, + cd:ControlDirective ) { this.domElement = ngElement.domElement this.config = Segment.config.invoke(this) this.elementRef = elementRef; this.renderer = renderer; + this.controlDirective = cd; + console.log('Segment with cd', cd); + + cd.valueAccessor = this; //ControlDirective should inject CheckboxControlDirective this.buttons = []; } + writeValue(value) { + console.log('SEGMENT WRITE VALUE', value); + } + bindButton(segmentValue) { this.buttons.push(segmentValue); let index = this.buttons.length; @@ -46,6 +62,8 @@ export class Segment { button.setActive(false); } segmentButton.setActive(true); + + this.value = segmentButton.value; } } diff --git a/ionic/components/segment/test/basic/main.html b/ionic/components/segment/test/basic/main.html index c8d1618241..f16a32431a 100644 --- a/ionic/components/segment/test/basic/main.html +++ b/ionic/components/segment/test/basic/main.html @@ -1,29 +1,32 @@ +
- - - Standard - - - Hybrid - - - Satellite - - + + --> - + + +
diff --git a/ionic/components/segment/test/basic/main.js b/ionic/components/segment/test/basic/main.js index cdc4c0d167..d6029220f6 100644 --- a/ionic/components/segment/test/basic/main.js +++ b/ionic/components/segment/test/basic/main.js @@ -9,6 +9,16 @@ import {IONIC_DIRECTIVES} from 'ionic/ionic' }) class IonicApp { constructor() { + + var fb = new FormBuilder(); + this.form = fb.group({ + mapStyle: ['', Validators.required] + }); + } + + doSubmit(event) { + console.log('Submitting form', this.form.value); + event.preventDefault(); } }