在angular2中使用ng-model和ng-control之间的区别? [英] Difference between using ng-model and ng-control in angular2?

查看:104
本文介绍了在angular2中使用ng-model和ng-control之间的区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 <form role="form" #form="form" (ng-submit)="submit(form.value)">
    <input type="text" placeholder="Enter your name" ng-control="name">
    <input type="text" placeholder="Enter your email" [(ng-model)]="email">
    <button>Submit</button>
  </form>

使用ng-model和ng-control的差异黑白是什么?什么时候使用它们?

What is the diff b/w using ng-model and ng-control? When to use each of them?

推荐答案

ngControlngModelngFormControl

ngControl, ngModel and ngFormControl are selectors for NgControlStatus directive, so there's no difference between them...

NgControlStatus 指令自动应用于基于控件状态(有效/无效/脏/等)设置CSS类的Angular表单.

NgControlStatus is Directive automatically applied to Angular forms that sets CSS classes based on control status (valid/invalid/dirty/etc).

NgFormControl 是绑定输入的指令模板中的 Control 类中的字段用于以编程方式创建表单字段.

NgFormControl is directive that binds input field in the template to the Control class that is used to programmatically create form fields.

NgFormControl 将现有控件绑定到DOM元素.

NgFormControl Binds an existing Control to a DOM element.

这篇关于在angular2中使用ng-model和ng-control之间的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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