user2218550
user2218550

Reputation: 147

ngModel value not updating

I have the below code written , on the paste event I want to change the ngModel value

<input [ngModel]="field[index].value" (paste)="field[index].value=myFunction($event)"/>

myFunction in component is as below:

   myFunction(event):string
    {
     //Some String processing
     return "pasted_processed_Value";
    }

However, I am able to log the processed string in myFunction method but the value returned from myFunction is not updated in ngModel

Upvotes: 0

Views: 1639

Answers (2)

John Velasquez
John Velasquez

Reputation: 3451

Make it a two-way binding instead -> [(ngModel)]

<input [(ngModel)]="field[index].value" (paste)="field[index].value=myFunction($event)"/>

Upvotes: 0

Leandro Lima
Leandro Lima

Reputation: 1164

<input [ngModel]="hello" (paste)="myFunction($event)"/>

myFunction(event):string
{
  //Some String processing
  this.hello = "pasted_processed_Value";
}

EDIT:

   (paste)="myFunction($event, field[index])"

   myFunction(event, field):string
    {
     //Some String processing
     field.value = "pasted_processed_Value";
    }

Upvotes: 1

Related Questions