Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

AngularJS Nested If Statement

Posted on 2014-10-23
5
Medium Priority
?
760 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 83

Accepted Solution

by:
leakim971 earned 2000 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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

When crafting your “Why Us” page, there are a plethora of pitfalls to avoid. Follow these five tips, and you’ll be well on your way to creating an effective page.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
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.
Any person in technology especially those working for big companies should at least know about the basics of web accessibility. Believe it or not there are even laws in place that require businesses to provide such means for the disabled and aging p…
Suggested Courses

876 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