mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-18 19:21:34 +08:00
SEGMENT
This commit is contained in:
@ -65,7 +65,7 @@ export class Segment {
|
||||
static get config() {
|
||||
return {
|
||||
selector: 'ion-segment',
|
||||
appInjector: [ NgFormControl ],
|
||||
appInjector: [ NgControl ],
|
||||
properties: [
|
||||
'value'
|
||||
],
|
||||
@ -85,7 +85,7 @@ export class Segment {
|
||||
}
|
||||
|
||||
constructor(
|
||||
cd: NgFormControl,
|
||||
cd: NgControl,
|
||||
elementRef: ElementRef,
|
||||
renderer: Renderer
|
||||
) {
|
||||
@ -135,9 +135,9 @@ export class Segment {
|
||||
*/
|
||||
selected(segmentButton) {
|
||||
for(let button of this.buttons) {
|
||||
button.setActive(false);
|
||||
button.isActive = false;
|
||||
}
|
||||
segmentButton.setActive(true);
|
||||
segmentButton.isActive = true;
|
||||
|
||||
//this.onChange();
|
||||
|
||||
@ -147,7 +147,7 @@ export class Segment {
|
||||
this.cd.valueAccessor.writeValue(segmentButton.value);
|
||||
this.selectFromValue(segmentButton.value);
|
||||
|
||||
this.cd.form.updateValue(segmentButton.value);
|
||||
this.cd.control.updateValue(segmentButton.value);
|
||||
|
||||
// Trigger on change
|
||||
this.change.next();
|
||||
@ -185,10 +185,6 @@ export class SegmentButton {
|
||||
this.segment.register(this);
|
||||
}
|
||||
|
||||
setActive(isActive) {
|
||||
this.isActive = isActive;
|
||||
}
|
||||
|
||||
buttonClicked(event) {
|
||||
this.segment.selected(this, event);
|
||||
event.preventDefault();
|
||||
|
@ -4,26 +4,21 @@ import {formDirectives, FormBuilder, Validators, Control, ControlGroup} from 'an
|
||||
import {IonicView} from 'ionic/ionic';
|
||||
|
||||
|
||||
@Component({ selector: 'ion-app' })
|
||||
@Component({
|
||||
selector: 'ion-app',
|
||||
appInjector: [FormBuilder]
|
||||
})
|
||||
@IonicView({
|
||||
templateUrl: 'main.html',
|
||||
directives: [formDirectives]
|
||||
})
|
||||
class IonicApp {
|
||||
constructor() {
|
||||
constructor(fb: FormBuilder) {
|
||||
|
||||
this.mapStyle = new Control("hybrid", Validators.required);
|
||||
this.form = new ControlGroup({
|
||||
"mapStyle": this.mapStyle
|
||||
});
|
||||
|
||||
/*
|
||||
var fb = new FormBuilder();
|
||||
this.form = fb.group({
|
||||
this.myForm = fb.group({
|
||||
mapStyle: ['hybrid', Validators.required]
|
||||
});
|
||||
*/
|
||||
console.log(this.form);
|
||||
console.log(this.myForm);
|
||||
}
|
||||
|
||||
doSubmit(event) {
|
||||
|
@ -1,7 +1,6 @@
|
||||
<ion-content class="padding">
|
||||
<form (^submit)="doSubmit($event)">
|
||||
<div ng-control-group="form">
|
||||
<ion-segment [ng-form-control]="mapStyle">
|
||||
<form (^submit)="doSubmit($event)" [ng-form-model]="myForm">
|
||||
<ion-segment ng-control="mapStyle">
|
||||
<ion-segment-button value="standard" button>
|
||||
Standard
|
||||
</ion-segment-button>
|
||||
@ -12,20 +11,19 @@
|
||||
Satellite
|
||||
</ion-segment-button>
|
||||
</ion-segment>
|
||||
</div>
|
||||
<button type="submit" button primary>Submit</button>
|
||||
</form>
|
||||
|
||||
Map mode: <b>{{form.controls.mapStyle.value}}</b>
|
||||
Map mode: <b>{{myForm.controls.mapStyle.value}}</b>
|
||||
|
||||
<div [switch]="form.controls.mapStyle.value">
|
||||
<div *switch-when="'standard'">
|
||||
<div [ng-switch]="myForm.controls.mapStyle.value">
|
||||
<div *ng-switch-when="'standard'">
|
||||
<h2>Standard</h2>
|
||||
</div>
|
||||
<div *switch-when="'hybrid'">
|
||||
<div *ng-switch-when="'hybrid'">
|
||||
<h2>Hybrid</h2>
|
||||
</div>
|
||||
<div *switch-when="'sat'">
|
||||
<div *ng-switch-when="'sat'">
|
||||
<h2>Satellite!!</h2>
|
||||
</div>
|
||||
</div>
|
||||
|
Reference in New Issue
Block a user