Solved

AngularJS Chaining IF Statement

Posted on 2014-10-24
1
104 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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
This tutorial demonstrates how to identify and create boundary or building outlines in Google Maps. In this example, I outline the boundaries of an enclosed skatepark within a community park.  Login to your Google Account, then  Google for "Google M…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

820 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