I have one very noob question for AngularJS expressions.
I want to check in expression (ngIf in this case) that something is
undefined. Eg:
data-ng-if="typeof obj.property == 'undefined'"
How I can write expression to check this?
I would be very grateful for any ideas and recommendations.
Best regards.
An undefined property will always be falsy, so you don't have to check it specifically unless you only care that it is undefined. A simply check could then be
data-ng-if="!user.email"
That would evaluate to true unless the user object had the property email with non-falsy value (0,'',undefined are all false). Maybe that is what you are after.
You can do this by using the negation operator:
data-ng-if="!(typeof obj.property == 'undefined')"
Also your call to typeof is a noop, it does nothing. You can simply remove it:
data-ng-if="!(obj.property == 'undefined')"
I agreee with #Matt Pileggi
but just to playing around
if('prop' in obj)
Related
I thought this would be something simple to do, but I don't think it's possible, why is that?
This is what I'm trying to do.
console.log("hello") ? bool : "";
This gives me an error: Expected an assignment or function call and instead saw an expression. Not sure exactly what that means.
From my understanding, you want to "conditionally" console.log via the tenery operator.
It is possible to conditionally (via ternary) change the output of console.log() based on a bool like so:
console.log(bool ? "hello" : "")
In this case though, it will output an empty string to the console.
My guess is that you only want to log if the bool is true. It's quite trivial to add a quick if statement:
if (bool) console.log('hello')
Via Ternary, if you ultimately wish to do this, you'd need to do something like the following:
bool ? console.log("test") : null;
In my opinion, this looks less cleaner than a simple bool statement as you'd need to provide some value (Simplest probably being null or 0) which is then assigned to nothing.
Yes. you have to evaluate the expression at runtime.
Do I like this.
const someBool = true;
console.log(someBool?'hello':'goodbye');
Now im really new to lua and need a little help with this This script checks some text on the player UI, and It works if It equals one thing for example : game:GetService("Players").LocalPlayer.PlayerGui.Main.Border.ClassLabel.Text == "UNIVERSELORD"
But does not work if I add the or game:GetService("Players").LocalPlayer.PlayerGui.Main.Border.ClassLabel.Text == "UNIVERSELORD" or "TANKTOP" It ends up doing it no matter what, and im not sure why, it works if I only put one name though, I would appreciate help thanks!
You already had the same question closed just few days ago due to the lack of details. It's not clear WHY you'd want to add "or" to a text, so you need to explain clearly and provide an example with some context where this usage would make some sense.
In terms of the "or" statement, it doesn't produce the result you want because it returns the first result that is evaluated as non-false, so when you have 1 or 2 expression, the result is 1, as it's evaluated left-to-right and this is a non-false results. Similarly in your case, the expression "UNIVERSELORD" or "TANKTOP" is evaluated to "UNIVERSELORD", as it's the first non-false value that is encountered.
Unfortunately nobody can tell you what to change it to, as there is not enough details in the question about your goal. Possibly an XY Problem.
[updated] Based on your comment, you need to split the or into two complete comparisons: game:GetService("Players").LocalPlayer.PlayerGui.Main.Border.ClassLabel.Text == "UNIVERSELORD" or game:GetService("Players").LocalPlayer.PlayerGui.Main.Border.ClassLabel.Text == "TANKTOP"
In Lua, any value that is not nil or false is considered true.
So in
if (game:GetService("Players").LocalPlayer.PlayerGui.Main.Border.ClassLabel.Text == "UNIVERSELORD" or "TANKTOP") then
getgenv().Spinloop = false print("Stopped!") return 0;
end
"TANKTOP" is a string and hence a true value.
or-ing anything with a true value is always true. So it does not matter if game:GetService("Players").LocalPlayer.PlayerGui.Main.Border.ClassLabel.Text equals "UNIVERSELORD". The result is always true. Hence your if condition is always met regardless of the text value.
Is there a way to handle null value for a field in XDocReport? or do I need to manipulate it on my own? example:
if (thisVar == null)
context.put("sampleText", "");
else
context.put("sampleText", thisVar);
or is there an option in docx quick parts?
I found this line in the error message of XDocReport. However I could not understand where to apply this, in the template or in the code.
Tip: If the failing expression is known to be legally refer to
something that's sometimes null or missing, either specify a default
value like myOptionalVar!myDefault, or use [#if
myOptionalVar??]when-present[#else]when-missing[/#if]. (These only
cover the last step of the expression; to cover the whole expression,
use parenthesis: (myOptionalVar.foo)!myDefault, (myOptionalVar.foo)??
In docx, append ?if_exists to the field name
«${tx.amount?if_exists}»
you may also append !
«${tx.amount!}»
Please refer to this link for those who uses freemarker. How to check if a variable exists in a FreeMarker template?
I am retrieving some data using stored procedure and calling it within the database connector in mule. I have to include a condition when I pass a value which is not there in the database it should capture the error. For this I am using a choice component where I have to check whether the payload is null. But when running the flow in debug mode I found that the payload holds the value
{resultSet1=[]}. I tried #[message.payload.isEmpty()], #[message.payload!=null] and #[payload.resultSet1 != null]. But they weren't working. Could anyone help to resolve this. Thanks in advance.
You can use empty to check for:
Testing for Emptiness: The special literal empty tests the emptiness of a value. It returns an empty value depending on context. empty evaluates to:
null
boolean false
empty strings or strings containing only white space
zero
empty collections
The expression #[foo == empty] evaluates to true if the value if foo satisfies any of the requirements for emptiness.
Which in your case would be
#[payload.resultSet1 != empty]
The best way is #[payload != null && payload.size()>0]
you can try comparing with 'null" or "0" or, simply, "empty" and it should work fine for you :)
#[payload == empty]
should work.
I have a loop that runs through a data set and determines the folder setup for a href. I have a ng-if for each of the options but I need to add a check to one of the ng-ifs. I need a way to check if a value is null. I have used something like:
ng-if="!shortcut.SAM3Link"
The problem with this is that if a value in my database is not null but does not have a value it does not recognize the difference. I need a way to specifically check for null rather than not having a value.
Basically I need a way to determine between a NULL value in my database and text/blank using a ng-if.
You need to use the Strict Equality Comparison:
ng-if="shortcut.SAM3Link === null"
ng-if - checking for null value of Array
ng-if="shortcut.SAM3Link === null"
ng-if="shortcut.SAM3Link.length === 0"