RangeError: Maximum call stack size exceeded when using valueChanges.subscribe

后端 未结 4 696
南方客
南方客 2021-02-02 08:30

I am using Angular 5 with Reactive forms and need to make use of the valueChanges in order to disable required validation dynamically

component class:

ex         


        
4条回答
  •  迷失自我
    2021-02-02 09:25

    My answer is just development of this one.

    By adding distinctUntilChanged() in the pipeline just before subscribe() you avoid the "Maximum call stack size exceeded" because

    distinctUntilChanged method only emit when the current value is different than the last.

    The usage:

    this.userForm.get('password')
      .valueChanges.pipe(distinctUntilChanged())         
      .subscribe(val => {})
    

    Documentation

提交回复
热议问题