Solved

AngularJS Chaining IF Statement

Posted on 2014-10-24
1
101 Views
Last Modified: 2014-11-18
I'm attempting to chain a group of variables to create a single IF statement. If I run each statement individually, I will get the expected results. Is there a better way to accomplish this?

                var upcomingDate = moment(object["upcomingdate"]);
                var monthlyDateFuture = moment().diff(upcomingDate, 'days') > 30 && object["Frequency"] == 'monthly';
                var biWeeklyFuture = moment().diff(upcomingDate, 'days') > 14 && object["Frequency"] == 'biweekly';
                var weeklyFuture = moment().diff(upcomingDate, 'days') > 7 && object["Frequency"] == 'weekly';
                var biMonthlyFuture = moment().diff(upcomingDate, 'days') > 60 && object["Frequency"] == 'bimonthly';
                var quarterlyFuture = moment().diff(upcomingDate, 'days') > 90 && object["Frequency"] == 'quarterly';

                if (monthlyDateFuture && biWeeklyFuture && weeklyFuture && biMonthlyFuture && quarterlyFuture) {
                       $scope.summary[segment].totalLateRelationships++;
                       $scope.summary[segment].lateRelationships.push(object);    
                }

Open in new window

0
Comment
Question by:brendanlefavre
1 Comment
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 40403931
look like you need OR operators not AND :
if (monthlyDateFuture || biWeeklyFuture || weeklyFuture || biMonthlyFuture || quarterlyFuture) {

Open in new window

0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo‚Ķ
Get to know the ins and outs of building a web-based ERP system for your enterprise. Development timeline, technology, and costs outlined.
The viewer will learn how to count occurrences of each item in an array.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question