实际上我在ionic2中使用复选框时遇到了问题。
我使用复选框作为:
<ion-item>
<ion-label>Agree</ion-label>
<ion-checkbox color="dark" id="agree" name='agree' class="form-control" formControlName="agree" [checked]="false" ></ion-checkbox>
</ion-item>
在.ts中,我的价值在于:
console.log(this.timelogForm.controls['agree'].value);
我希望它最初不受限制。
我的问题是:
请帮忙
我自己解决了这个问题,希望能有所帮助。
我将其值设置为false,如:
this.logForm = formBuilder.group({
'agree': ['false'],
});
希望它可以帮助某人。
buildForm(){
this.accountForm = this.formBuilder.group({
generalTerms: ['', Validators.requiredTrue]
});
}
<form [formGroup]="accountForm">
<ion-item class="center">
<ion-checkbox formControlName="generalTerms" checked="false"></ion-checkbox>
<ion-label>Accepter les conditions générale</ion-label>
</ion-item>
<ion-item class="button" lines="none">
<ion-button color="primary [disabled]="accountForm.invalid"
(click)="save()">
Valider
</ion-button>
</ion-item>
</form>
它的工作。我希望它会对你有所帮助。
test.ts
import { Component } from '@angular/core';
import { NavController, Events } from 'ionic-angular';
import { FormGroup, FormBuilder, Validators } from '@angular/forms';
@Component({
templateUrl: 'test.html'
})
export class test implements OnInit {
logform: FormGroup;
forgotPasswordEmail: any;
constructor(private _navCtrl: NavController, private _fb: FormBuilder) { }
ngOnInit() {
this.logform = this._fb.group({
ckeckbox: ['false', Validators.required]
});
}
}
的test.html
<ion-item>
<ion-label>Daenerys Targaryen</ion-label>
<ion-checkbox color="dark" formControlName="ckeckbox" checked="false"></ion-checkbox>
</ion-item>