表单中的Angular 2回滚模型状态 [英] Angular 2 rollback model state in forms

查看:44
本文介绍了表单中的Angular 2回滚模型状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Angular 2中有一个绑定到模型的表格.现在,我希望在用户单击取消"时回滚模型中的更改.我该如何实现?

I have a form in Angular 2 which is bound to a model. Now I want the changes in the model to rollback when the user hits cancel. How do I achieve this?

推荐答案

我将重复评论中讨论的内容(因为我不喜欢SO的未回答问题)

I'll repeat what was discussed in the comments (because I don't like unanswered questions on SO):

  • 对于许多用例,您可能可以使用与
  • For many use cases, you can probably use something very similar to the RestoreService that is discussed in the Hierarchical Injectors dev guide.
  • For the OP's particular case, where the model is bound to another component and live form changes need to be reflected in the other component, make a copy of your model before displaying the form. If the user cancels, revert to the copy, and notify the other component to use the copy also (i.e., send it the copy).

这篇关于表单中的Angular 2回滚模型状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆