I am facing a problem in checkbox they are always checked. When I add an object in database contains checkbox, it always shows checked checkbox when I open the edit page in my application !
this is my ts file :
code: string;
isDefault: boolean;
obj: Typestation= new Typestation();
constructor( private formBuilder: FormBuilder,private typestationservice:TypestationService) {
}
ngOnInit() {
this.typestationservice.getTypeStationById(this.id).then(resp => {
this.obj = resp;
console.log("testtt",resp)
});
this.messageForm = this.formBuilder.group({
code: [''],
libelle: [''],
isDefault: [''],
active: ['']
});
}
onSubmit() {
this.submitted = true;
if (this.messageForm.invalid == false) {
this.success = true;
let obj = this.messageForm.value;
obj.id = this.id;
this.typestationservice.updateTypeStation(obj).then(resp => {
this.exit();
})
}
}
and this is my Html file:
<div class="col col-xl-3 col-lg-4 col-md-6 col-sm-6 col-12">
<div class="form-group row">
<label for="isDefault" class="costum_Font-size"> </label>
<div class="col-12">
<mat-checkbox id="isDefault" formControlName="isDefault" class="form-control" name="isDefault" ngModel [(ngModel)]="obj.isDefault">
isDefault
</mat-checkbox>
</div>
</div>
</div>
<div class="col col-xl-3 col-lg-4 col-md-6 col-sm-6 col-12">
<div class="form-group row">
<label for="active" class="costum_Font-size"> </label>
<div class="col-12">
<mat-checkbox id="active" formControlName="active" class="form-control" name="active" ngModel [(ngModel)]="obj.active">
Actif
</mat-checkbox>
</div>
</div>
</div>
my model:
export class Typestation{
public id: string;
public code: string;
public libelle: string='';
public active: boolean;
public isDefault:boolean;
}
Can anyone help me to fix this problem !
Aucun commentaire:
Enregistrer un commentaire