How can I bind data in ngFor?

Published

I have a problem in input text, when I write in one input it changes in the other input as well ! how can I fix that !
HTML code:

  <mat-expansion-panel  class="childPanel" [expanded]="true" hideToggle disabled style=" background:#F2EDFF;" *ngFor="let i of listSousCategorie"   >
            <div class="childPanel_body2 mat-badge-large" fxLayout="row" fxFlex fxLayoutAlign="start center"  >
              <div style="padding-left:1em" fxFlex="grow" >{{i.libelle}} {{i.id}}</div>
              <mat-form-field  >
                <form [formGroup]="form" (ngSubmit)="onSubmit(i.id)">
                <mat-label>Note</mat-label>
                <input  type="text" matInput  formControlName="Note" [(ngModel)]="Note" >
              </form>
              </mat-form-field>
            </div>
          </mat-expansion-panel>

TS Code:

Note:string;

     ngOnInit() {
        this.form = this.formBuilder.group({
          Note: [''],
        });
      }
    
              onSubmit(id:number) {
                  let obj = this.form.value;
                  obj.Note = this.Note;
            
                  console.log(this.Note)
                  this.LExamenSousCategorieService.updateSouCategorie(obj,id).then(res => {
                  })
                } 

enter image description here

Source: Angular Questions

Published
Categorized as angular, html Tagged ,

Answers

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Still Have Questions?


Our dedicated development team is here for you!

We can help you find answers to your question for as low as 5$.

Contact Us
faq