Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/32.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在angular2中使用ng模型和ng控制之间的差异? 提交_Angular - Fatal编程技术网

在angular2中使用ng模型和ng控制之间的差异? 提交

在angular2中使用ng模型和ng控制之间的差异? 提交,angular,Angular,使用ng模型和ng控制的差异是什么?何时使用它们?控件负责获取有关表单状态或特定输入(有效、原始、触摸等)的提示。它通常用于显示验证错误(如果有)。以下是一个示例: <form role="form" #form="form" (ng-submit)="submit(form.value)"> <input type="text" placeholder="Enter your name" ng-control="name"> <input typ

使用ng模型和ng控制的差异是什么?何时使用它们?

控件负责获取有关表单状态或特定输入(有效、原始、触摸等)的提示。它通常用于显示验证错误(如果有)。以下是一个示例:

 <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>
因为它是可观察的,所以您可以利用操作员创建一个不连续的处理链。例如,要根据输入同步列表,请执行以下操作:

this.inputControl.valueChanges.subscribe(data => {
  console.log('value updated - new value = '+data);
});
另一方面,
ngModel
允许使用双向绑定将输入绑定到组件的属性。如果属性由代码更新,则输入值将更新;如果输入由用户更新,则属性将更新


正如@Günter所指出的,您的代码片段包含一些错误。这是正确的一个:

inputControl.valueChanges.debounceTime(500).flatMap(
  val => {
    return this.service.searchPlaces(val);
  }).subscribe((data) => {
    this.places = data;
  });

提交

ngControl
ngModel
ngFormControl
是指令的选择器,所以它们之间没有区别

NgControlStatus指令自动应用于角度窗体,该窗体根据控件状态(有效/无效/脏/等)设置CSS类

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

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


自大约beta.49以来,Angular2中没有
ng提交
ng控制
ng模型
。它们应该是
ngSubmit
ngControl
ngModel
。是。对的还有什么区别?
inputControl.valueChanges.debounceTime(500).flatMap(
  val => {
    return this.service.searchPlaces(val);
  }).subscribe((data) => {
    this.places = data;
  });
<form role="form" #form="form" (ngSubmit)="submit(form.value)">
  <input type="text" placeholder="Enter your name" ngControl="name">
  <input type="text" placeholder="Enter your email" [(ngModel)]="email">
  <button>Submit</button>
</form>