Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

AngularJS Nested If Statement

Posted on 2014-10-23
5
Medium Priority
?
715 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Does your audience prefer people in photos or no people? How can you best highlight what you’re selling? What are your competitors doing, and what can you do that is different and unique from them?  Continue reading to learn how to make your images …
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?
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:
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.
Suggested Courses

670 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