angular - 在组件之间交换时如何防止表单数据丢失(不刷新)?
问题描述
我在 2 个组件(都包含表单)之间交换,但我想保留用户在表单中写入的数据(不提交),即使在交换组件之后也是如此。它通过在选项卡之间交换来处理简单的 html
我正在尝试根据父组件中名为“值”的变量交换组件。
父组件html:
<ul>
<li class="nav-item"><a (click)="changeValue(1)">Dine In</a></li>
<li class="nav-item"><a(click)="changeValue(2)">Delivery</a></li>
</ul>
</div>
<app-dine *ngIf="value == 1"></app-dine>
<app-delivery *ngIf="value == 2"></app-delivery>
在父 ts 我做了一个简单的 cahngevalue 函数:
changeValue(x){
this.value=x;
}
子组件只是表单:例如:
<form>
<input type="text"> //if the user write anything here i want to swap components to the other child without losing data
</form>
请帮忙。谢谢!
解决方案
它通过使用
[hidden]="value === x"
在组件条件下而不是交换它。
推荐阅读
- arrays - 查找满足某些约束的无序行对的索引
- botframework - LUIS - 实体类型列表,如何最好地使用?
- scala - 如何将 Java 库包含到 scala 项目中
- python - python - object() 没有参数错误
- bash - 如何在内部 sudo-bash 脚本中访问 $USER?
- python - 多数组计算中的cupy执行错误
- c++ - 如何查找数组中是否有任何重复元素?C++
- excel - 如何在另一个 vba excel 中获取某一列中某些值的总和
- python - Visual Studio Code - Python 调试 - 执行时步入外部函数的代码
- c++ - C ++ Map Iterator查找重复次数最多的单词