angular - 如何获取有关输入表单值 Angular 的旧数据
问题描述
我在 Angular 中使用此表单更新数据。单击重置按钮时,我想获取旧输入的值。你们能帮帮我吗?
<form #myform="ngForm" (ngSubmit) = "onSubmit(myform)" class="form form-register">
<mat-form-field fxLayout="row" appearance="outline" >
<label for="name">Name: </label>
<input name="name" id="name" type="text" [(ngModel)]="list['name']" required>
</mat-form-field>
<mat-form-field fxLayout="row" appearance="outline" >
<label for="Location">Location: </label>
<input name="location" id="location" type="text" [(ngModel)]="list['location']" required>
</mat-form-field>
<input type="hidden" #charactername="ngModel" [(ngModel)]="list['id']" name="id">
<div>
<input type="reset" value="Reset" (click)="clearForm(myform)">
<input type="submit" value="Register">
</div>
</form>
解决方案
在创建“列表”的同时,将其值复制到另一个变量。然后在 clearForm() 中,将值复制回“列表”。您甚至可以删除参数“myForm”,因为它包含的值对您没有帮助。
推荐阅读
- qt - 如何在QT中安装gumbo?
- c - 配置后删除未使用的宏和代码
- laravel - React 在生产环境中随机抛出错误
- javascript - Play and pause on webp animated images
- php - How Should I save input values of HTML form in sql from php
- c++ - Rotate NxM Matrix Efficiently when Represented as a One Dimensional Vector of Objects (C++)
- typescript - 打字稿 - 通用实现
- ios - 在“PSPDFViewController *”类型的对象上找不到属性“pagingScrollView”
- ionic-framework - Error while building android apk in ionic 3
- php - PHPMailer emails NOT sending sometimes because of multiple tests?