Solved

AngularJS Nested If Statement

Posted on 2014-10-23
5
469 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

New My Cloud Pro Series - organize everything!

With space to keep virtually everything, the My Cloud Pro Series offers your team the network storage to edit, save and share production files from anywhere with an internet connection. Compatible with both Mac and PC, you're able to protect your content regardless of OS.

Question has a verified solution.

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

Suggested Solutions

Learn by example how to specify CSS selectors for Selenium WebDriver test automation software.
This article discusses how to create an extensible mechanism for linked drop downs.
Viewers will get an overview of the benefits and risks of using Bitcoin to accept payments. What Bitcoin is: Legality: Risks: Benefits: Which businesses are best suited?: Other things you should know: How to get started:
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

911 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now