madhura21
madhura21

Reputation: 43

Less if else conditions in angularjs

I have 2 main dates : MainFrom and MainTo Depending on these , I have set validations for my work experience date validations in angularjs(I know, it is old but the proejct was written in this version). I can add from and to experience dates.Validation needed:

  1. Main From date > Main To date
  2. other Experince dates should be between these dates.
  3. Other work experience to date should be greater than from date.

I have written lot of conditions to check these. Could someone suggest less lines of code?

Upvotes: 0

Views: 43

Answers (1)

Vikram Verma
Vikram Verma

Reputation: 51

to go with the trend these day try moment in you angularjs app, first include moment js in your project, the lib will help you in all validations and checks related to dates.

for eg in your cases validation check will something like this:

Main From date > Main To date :

 if(moment(Main From date).isAfter(Main To date))

other Experince dates should be between these dates. : loop on every date

if(moment(other Experince dates).range(startDate, endDate);)

Other work experience to date should be greater than from date.

if(moment(to date).isAfter(Main from date))

Upvotes: 2

Related Questions