Solved

AngularJS Nested If Statement

Posted on 2014-10-23
5
571 Views
Last Modified: 2014-10-23
I'm trying to add a bit of logic to my controller with a couple of nested If statements. By themselves they work fine, but after nesting them, i'm not getting any results.

This is a working statement:
            if (typeof object["Frequency"]!='undefined' && object["Frequency"]=='yearly' && ('now' <= 'upcoming')) {
            $scope.summary[segment].totalLateRelationships++;
            $scope.summary[segment].lateRelationships.push(object);
        } 

Open in new window


This is working:
        if (!(object["nextmeetingowner"].length) || !(object["Last Meeting Date"].length) ) {
            $scope.summary[segment].totalLateRelationships++;
            $scope.summary[segment].lateRelationships.push(object);
        }

Open in new window


This is what I'm trying to accomplish:
            if (!(object["primaryaccountability"].length) || (!(object["nextmeetingowner"].length))) {
          if  (typeof object["Frequency"]!='undefined' && object["Frequency"]=='yearly' && ('now' <= 'upcoming'))
            {
                $scope.summary[segment].totalLateRelationships++;
                $scope.summary[segment].lateRelationships.push(object);
            }
        }

Open in new window

0
Comment
Question by:brendanlefavre
  • 2
  • 2
5 Comments
 
LVL 58

Expert Comment

by:Gary
ID: 40400899
The two seperate statements are not the same as you have merged.

if (!(object["nextmeetingowner"].length) || !(object["Last Meeting Date"].length) ) {

if (!(object["primaryaccountability"].length) || (!(object["nextmeetingowner"].length))) {
0
 

Author Comment

by:brendanlefavre
ID: 40400932
this should be the correct one

                if (!(object["nextmeetingowner"].length) || !(object["nextmeetingowner"].length) ) {
                    $scope.summary[segment].totalLateRelationships++;
                    $scope.summary[segment].lateRelationships.push(object);
                }

Open in new window

0
 
LVL 58

Expert Comment

by:Gary
ID: 40400937
What is your real original code.
The above has the same variable in the condition
0
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 40400945
var frequencyIsNotUndefined = typeof object["Frequency"] != 'undefined';
var frequencyIsSetToYearly = object["Frequency"] == 'yearly'; 
var nowIsBeforeUpcoming = 'now' <= 'upcoming'; // ??? ALWAYS TRUE
var nextmeetingownerIsFilled = !object["nextmeetingowner"].length;
var LastMeetingDateIsFilled = !object["Last Meeting Date"].length;
if( frequencyIsNotUndefined && frequencyIsSetToYearly && nowIsBeforeUpcoming && nextmeetingownerIsFilled && LastMeetingDateIsFilled ) {
            $scope.summary[segment].totalLateRelationships++;
            $scope.summary[segment].lateRelationships.push(object);
} 

Open in new window


http://jscompress.com/
https://www.npmjs.org/package/gulp-uglify
http://gulpjs.com/
0
 

Author Closing Comment

by:brendanlefavre
ID: 40400964
This solution makes much more sense than the approach I was using
0

Featured Post

Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

Question has a verified solution.

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

Suggested Solutions

Because your company can’t afford for you to make SEO mistakes, you’ll want to ensure you’re taking the right steps each and every time you post a new piece of content. This list of optimization do’s and don’ts can help you become an SEO wizard.
Color can increase conversions, create feelings of warmth or even incite people to get behind a cause. If you want your website to really impact site visitors, then it is vital to consider the impact color has on them.
The viewer will learn how to count occurrences of each item in an array.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

821 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