Home:ALL Converter>Angular 5 does not check multiple conditions

Angular 5 does not check multiple conditions

Ask Time:2018-06-08T22:00:14         Author:Hoàng Nguyễn

Json Formatter

I create a method to submit a form, and inside that method I have to check 2 conditions which are created in 2 different other methods before submitting the form, but I don't even know why, only the first condition is triggered, the second one is never called, no matter which conditional method I put first. Can anyone explains this, I could not even find a similar problem on the Internet?

component.ts:

onSubmit(formValues) {
  if (editedForm.status === 'Ready') {
    // no matter what conditional method is called first, only the 
    // first condition is checked
    if (this.isNotOverlapped() && this.isValidPeriodOrder()) {
      this.apiService.submit(formValues).subscribe(() => {
       // sending data to backend....
      });
    }
  }
}

// conditional method
isNotOverlapped(): boolean {
  console.log('IsNotOverlapped fire!');
  let isvalid = false;
  if (this.data.length > 1) {
   // some validation stuffs
  }
  return isvalid;
}

// conditional method
isValidPeriodOrder(): boolean {
  console.log('IsValidPeriodOrder fire!');
  let isvalid = false;
  if (this.data.length > 1) {
   // some validation stuffs
  }
  return isvalid;
}

Author:Hoàng Nguyễn,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/50762348/angular-5-does-not-check-multiple-conditions
yy