如何获得HTML值传递给javascript或通过环回使用两种方式绑定?

时间:2019-05-23 17:17:53

标签: angular

HTML:

<input #box (keyup)="0" value="" >
<p>{{box.value}}<p> 

->好的

javascript:

let i = {{box.value}}

->失败 如何在此处传递html值?

我尝试使用n g模型,但失败了

还是如何通过环回使用双向绑定?

因为我需要<p></p>实时显示输入

1 个答案:

答案 0 :(得分:0)

{
"Question": "Question test",
"cod" : "pw3"
"Value" : "10"
  "Alternatives": [
    {
      "test": "test",
      "test2": "test",
      "test3": "test"
    },
  ]
}

在您的代码中

<table>
    <thead><tr><th>Name</th><th>Action</th></tr>
    </thead>
    <tbody>
      <tr *ngFor="let quiz of quizes">
        <td>
          <input name="alternativa" type="text" [(ngModel)]="quiz.pergunta" [disabled]="!quiz.isEditable"/>
        </td>
        <td>
          <button (click)="quiz.isEditable=!quiz.isEditable" *ngIf="!quiz.isEditable">Edit</button>
          <button *ngIf="quiz.isEditable" (click)="quiz.isEditable=!quiz.isEditable">Save</button>
        </td>
      </tr>
    </tbody>
  </table>

  <div class="ui-g-2 ui-md-2 ui-lg-2 ui-fluid espacamento-baixo">
    <p-button label="Salvar"></p-button>
  </div>