Thomas Degroot
Thomas Degroot

Reputation: 524

How do I insert a variable into ion-textarea with typescript without using ngModel

I am trying to add the text results of a method called by (click)="runMatrix()" on line 4 into ion-textarea on line 7. Normally I would use an ngModel, but I cannot in this case as I am using ngModel to save the data.

.html

<div *ngFor="let fromItem of importQuestions let i = index">
  <ion-card>  
    <ion-card-content>
      <div class="question_link" (click)="openMatrix()">
      {{fromItem.Question}}
      </div>          
      <ion-textarea auto-grow="true" id="fromItem.ID" name="{{fromItem.name}}" [(ngModel)]="fromItem.input""> </ion-textarea>
    </ion-card-content>
  </ion-card>

  <ion-card>
    <ion-card-content>
      <div class="question">
        {{fromItem.Question}}
      </div>
      <ion-select multiple="true" name="{{fromItem.name}}" [(ngModel)]="fromItem.input">
        <ion-select-option *ngFor="let item of importQuestions[i].values" value="{{item.value}}">{{item.value}}</ion-select-option>
      </ion-select>
    </ion-card-content>
  </ion-card> 
</div>

The (click)="runMatrix() method returns a string

 this.resultNumber

I did not include the method as it is quite large.

How would I get the resultNumber into the input text area of of the ion-textarea after running the method?

Upvotes: 0

Views: 287

Answers (1)

Pallamolla Sai
Pallamolla Sai

Reputation: 2493

I think on line 4 it should be runMatrix() as you mentioned(In question it was openMatrix). On line 4 make change as below.

// passing index no to runMatrix
<div class="question_link" (click)="openMatrix(i)">

In your runMatrix() method get the index number make change as below.

runMatrix(index) {
     // your logic here 
     // adding updated value to the specific index no.of importQuestions
     this.importQuestions[index].input = "yourResultNumber"
}

Upvotes: 2

Related Questions