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

后端 未结 4 693
南方客
南方客 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:10

    The problem is that you modify the value of the field inside of the valueChanges event handler for that same field, causing the event to be triggered again:

    this.userForm.get('loginTypeId').valueChanges.subscribe(
      (loginTypeId: string) => {
        ...
        this.userForm.get('loginTypeId').updateValueAndValidity(); <-- Triggers valueChanges!
    }
    

提交回复
热议问题