mercredi 5 mai 2021

ion-checkbox pre-seleted from API side

I am gone through many solutions!

i have one checkbox in my ionic app. i am use reactive from in this app. i call one api to get list of data of checkbox -

 "Result": [
    {
        "Subject_Id": 1
    }
]

In this i got one subject id selected from api side.

i share my code -

//ts
getSchemeDetail() {
    this.api
      .post(
        this.api.url + "GetStudentList",
        { StudentId: this.Student.StudentId },
        false
      )
      .then((data: any) => {
     
          this.studentForm.patchValue({ 
          sub: data.sub_Id
          });
        }
        setTimeout(() => {
          this.getStudentList();
        }, 1000);
      })
      .catch((error: any) => {
        this.common.dismissLoading();
      });
  }
  
   getStudentList() {
    this.api
      .post3(
        "subjectid",
        {
          StudentId: this.studentId,
        }, true )
      .then((data: any) => {
        this.SubList = data.Result;
        setTimeout(() => {
            this.studentForm.patchValue({ sID: this.sid });
            if (this.vid == this.SubList) {
              this.isChecked = true;
            } else {
              this.isChecked = false;
            }
          
        }, 100);
      })
      .catch((error) => {
        console.log("State Error => ", error);
      });
  }

and my HTML code is

   //Html code
 <div *ngFor="let vm of SubList">
           <ion-checkbox color="primary" type="checkbox" formControlName="sID" [(ngModel)]="s.isChecked" >
</div>

i am getting all check box checked.

so how can i get only show that selected check box from the API side




Aucun commentaire:

Enregistrer un commentaire