How to give multiple condition in ng-class - angularjs

Have to implement scenario where both && and || should work in one expression like below
ng-class = "{'class_name' : condition1 || condition2 || (condition3 && condition4)}"
Its possible if yes then how?

It should work the way you wrote it, if it doesn't make sure you have the right starting and closing of brackets and parenthesis. It would be helpful if you post your code here. If you want to understand more using ng-class, you can go through the following well-written article.
https://scotch.io/tutorials/the-many-ways-to-use-ngclass

#Dan Thank you so much for your comment.
as question This not working directly but using the function works perfect.

Related

Handling an expression outside of a repeat in ng-class

Can someone please let me borrow your eyes for a second because this has to be some dumb little nuance I'm missing here...?
So as example, within an ng-repeat I pull out a value and throw an inline expression at it like this (in this example, just changing some text color based on how many days old the value is):
EDIT* - scope.item doesn't mean anything in particular, I just edited the verbiage a little to get rid of any identifying names for the sake of an internet example.
ng-class="{
'green-text':{{daysSinceToday(item.theItemDate) <= 20}},
'orange-text':{{daysSinceToday(item.theItemDate) > 20 && daysSinceToday(item.theItemDate) < 30}},
'red-text':{{daysSinceToday(item.theItemDate) >= 30}}
}">
Which works splendidly, except then when I'm outside of the scope of the ng-repeat and try something similar but using just [0] on the item index like you see, then I can still get the value to display, but it doesn't seem to care about the ng-class expressions at all and instead just grabs the first class listed in the ng-class no matter what the value is.
So if I do something like this OUTSIDE of the ng-repeat;
ng-class="{
'someclass':{{daysSinceToday(scope.item[0].theItemDate) <= 20}},
'anotherclass':{{daysSinceToday(scope.item[0].theItemDate) > 20 && daysSinceToday(scope.item[0].theItemDate) < 30}},
'yetanotherclass':{{daysSinceToday(scope.item[0].theItemDate) >= 30}}
}">
It just doesn't seem to care, which is weird because if I just put it in there raw like;
{{daysSinceToday(scope.item[0].theItemDate)}}
Without the expression, it DOES give me the correct value but seems to ignore the ng-class. What am I missing here? I must be tired, and this monday should end on a high note lol. Thanks!
Hah! File under I Blame Lack Of Caffeine, you want:
ng-class="{
'someclass':daysSinceToday(scope.item[0].theItemDate) <= 20,
'anotherclass':daysSinceToday(scope.item[0].theItemDate) > 20 && daysSinceToday(scope.item[0].theItemDate) < 30,
'yetanotherclass':daysSinceToday(scope.item[0].theItemDate) >= 30
}">
...no curlies necessary inside the ng-class.
(The rules for when you need {{}} and when you don't are arbitrary and confusing easy to overlook, as demonstrated quite clearly here)
You shoudn't be accessing it as scope.item[0].
I am not sure what is the variable you are iterating in ng-repeat but, assuming you are using something like items, you should access it just with items[0].whatever(...

What does the __default__ prefix mean in ng-inspector?

What exactly does the __default__ prefix mean in ng-inspector as shown below?
I am trying to access this value and I'm not quite sure how.
Thanks!
The extension certainly didn't add that prefix, if it shows up in ng-inspector, something else added that to your model.

How to make an if statement in c with two conditions?

It is a simple question, but what is the proper way to write an if statement in C that has 2 conditions?
For example:
if (input < 400 & input > 250){
some action...
}
Thanks!
Ok your question seems to be particularly unpopular...
just for info, have a look at http://en.wikipedia.org/wiki/Operators_in_C_and_C%2B%2B
The operator you are looking for is && but I should not tell you this since in fact as downvotes testify... your question is a bit lazy!
I also know that sometimes when you are a noob it can be diffcult to find the correct terms for google.
good luck!

How can I compare two values in angularjs in HTMl

How can I compare two scope values using angularjs in HTML only?
for example:
<div ng-if="place.id = place.reference.id"> show if equals</div>
I want this to cover certain scanrios
You are assigning something this way...
To check for equality you need == or ===, but 3 should be used as Doug says -
"If there is every anything that causes unwanted effects and can be
solved by something else, use the something else..."
Ok maybe he didnt say that exactly but you get the point....
<div ng-if="place.id === place.reference.id"> show if equals</div>

purpose of if (true)

I've seen some code written like this:
if (true) {
... // do something
}
Why would you want to do something like this? Is there any thing special about this structure?
THanks
Pretty much any modern compiler would just optimize this away. My guess is that someone put it there during development to let them easily remove a block of code (by changing true to false), and either forgot or didn't bother to remove it when they were done.
This is one of many ways to segment out code during testing/development. Many might debate whether or not it is good coding practice, but it can be a quick and handy way to compartmentalize code. It is also a quick way to execute code that follows a complex conditional statement that you want to test.
Might be able to use it like this:
/* if (my_comlex_or_rare_conditional_case) then */
if (true) then
{
lots of code here....
} /*End if */
There have been times where I've added true || or false && inside a condition to force it to execute the branch and test the code - but only during development. The code you've posted doesn't need the if condition.

Resources