Skip to content

Instantly share code, notes, and snippets.

@jhonatasfender
Last active December 21, 2022 17:12
Show Gist options
  • Save jhonatasfender/ec8bd189b58170124fb1b32b6c61d46f to your computer and use it in GitHub Desktop.
Save jhonatasfender/ec8bd189b58170124fb1b32b6c61d46f to your computer and use it in GitHub Desktop.
Como fazer para parar o loop

Nesse código a baixo tem um exemplo para poder entender como parar um loop

image

merge(
  controlForm.get('startDate').valueChanges,
  controlForm.get('endDate').valueChanges
).subscribe(() => {
  // console.log(data)
  const start = moment(controlForm.get('startDate').value);
  const end = moment(controlForm.get('endDate').value);

  if (start.isValid() && end.isValid()) {
    controlForm
      .get('durationInDays')
      .setValue(end.diff(start, 'days') + 1, {
        emitEvent: false,
      });
  }
});

controlForm
  .get('durationInDays')
  .valueChanges.pipe(distinctUntilChanged())
  .subscribe((days: number) => {
    const end = moment(controlForm.get('endDate').value);

    if (end.isValid()) {
      controlForm
        .get('startDate')
        .setValue(end.subtract(days, 'days').toDate(), {
          emitEvent: false,
        });
    }
  });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment