How can I run only one subscription when both controls change simultaneously in Angular?

39 Views Asked by At

I have 2 controls and subscriptions for them in my.ts file

 this.Control1.valueChanges
        .pipe(
            startWith(this.Control1.value),
            distinctUntilChanged(),
            takeUntil(this.innerControlUnsubscribe$)
        )
        .subscribe(() => {
            this.meth1();
            this.cdr.markForCheck();
        });

    this.Control2.valueChanges
        .pipe(
            startWith(this.Control2.value),
            distinctUntilChanged(),
            takeUntil(this.innerControlUnsubscribe$)
        )
        .subscribe(() => {
            this.meth2();                
            this.cdr.markForCheck();
        });

So, if any of these controls changes, either meth1 or meth2 is called, and that works fine. However, I have an additional condition: if both controls change simultaneously, run the subscription only for Control2. How can I achieve this?

0

There are 0 best solutions below