subscribe to valueChanges from input FormControl in FormGroup

后端 未结 3 641
轻奢々
轻奢々 2021-01-01 09:28

In Angular 4, I\'m trying to subscribe to the valueChanges of a FormControl. Neither of the versions below is working. I\'m not seeing any errors. The form.value JSON is upd

3条回答
  •  天命终不由人
    2021-01-01 09:56

    I gave up on FormGroup and FormBuilder and just used

    HTML:

     
    

    App class:

    firstName = new FormControl();
    

    ngOnInit:

    this.firstName.valueChanges.subscribe(value => {
         console.log('name has changed:', value)
    });
    

    My test is currently broken with the error "No provider for NgControl" but I'll work on that next. Update: I just needed to import ReactiveFormsModule in the TestBed

提交回复
热议问题