【问题标题】:How do I insert a variable into ion-textarea with typescript without using ngModel如何在不使用 ngModel 的情况下使用 typescript 将变量插入到 ion-textarea
【发布时间】:2019-11-26 21:32:32
【问题描述】:

我正在尝试将第 4 行 (click)="runMatrix()" 调用的方法的文本结果添加到第 7 行的 ion-textarea 中。通常我会使用 ngModel,但在这种情况下我不能我正在使用 ngModel 来保存数据。

.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>

(click)="runMatrix() 方法返回一个字符串

 this.resultNumber

我没有包含该方法,因为它非常大。

运行该方法后,如何将 resultNumber 放入 ion-textarea 的输入文本区域?

【问题讨论】:

  • 这个问题有点混乱,能不能简单点?
  • 请问我的回答有帮助吗?
  • 不抱歉。我可能问得不好。 runMatrix() 返回类似“some text here”的内容。我必须想办法把它放到 textarea 的输入字段中。我不能使用 index 或 ngModel,因为它们被用来提取和保存数据
  • 你想像这样添加 "some string returned by runMatrix"
  • 是的,这就是我想要做的

标签: angular ionic4


【解决方案1】:

我认为在第 4 行它应该是你提到的 runMatrix()(有问题的是 openMatrix)。在第 4 行进行如下更改。

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

在您的 runMatrix() 方法中获取索引号,如下所示进行更改。

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

【讨论】:

  • 我会将其标记为正确答案,因为 runMatrix 中的第四行让我正在研究可行的解决方案
猜你喜欢
  • 2017-07-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-04-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多