简体   繁体   English

何时在 Angular 中使用模板驱动和反应式 forms

[英]When to use template driven & reactive forms in Angular

I have read a lot of articles about the differences about the 2 types of forms in angular but nowhere found practical examples.我已经阅读了很多关于 angular 中两种 forms 的差异的文章,但没有找到实际示例。 So, if I have a table, and only a checkbox to select rows, is there any good reason to use reactive form?那么,如果我有一个表格,并且只有一个 select 行的复选框,那么有什么好的理由使用反应形式吗? I can't find any reason not to use the template driven method.我找不到任何不使用模板驱动方法的理由。

Select row in a table with checkbox... Template or Reactive?? Select 表中带有复选框的行...模板还是反应式?

Search input above this table... Template or Reactive??在此表上方搜索输入...模板或反应式?

(No validation) (无验证)

Ideally when you have something to do which takes the control back to the business logic, you should use reactive forms.理想情况下,当您有事情要做而将控制权带回业务逻辑时,您应该使用反应式 forms。

If you want something very short and sweet which is for eg, validating numbers or minLen or maxLen stuff, then template driven forms are the best.如果你想要一些非常简短和甜蜜的东西,例如验证数字或 minLen 或 maxLen 的东西,那么模板驱动的 forms 是最好的。 For complex validations, we may require to use reactive forms.对于复杂的验证,我们可能需要使用反应式 forms。

I hope this helps.我希望这有帮助。 Thank you.谢谢你。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM