如何订阅Angular2中表单组的一个键的变化

How to subscribe to changes of only one key of form group in Angular2

我有一个 userForm 组,其中包含键 nameemailphone。我还有一个 onValueChanged 函数,可以订阅表单更改并验证 nameemailphone。并且 onValueChanged 每次运行,当 nameemailphone 更改但我不想验证时,例如 name,如果名称不'改变。解决我的问题的正确方法是什么?

 buildForm(): void {
    this.userForm = this.fb.group({
      'name': ['', [
          Validators.required,
        ]
      ],
      'email': [''],
      'phone':    ['', Validators.required]
    });

this.userForm.valueChanges
  .subscribe(data => this.onValueChanged(data));

你可以这样做

this.userForm.controls['name'].valueChanges(...)