I have condition like this
<table ng-if="name=='john' && name=='MARK'">
//rest of the code
</table>
My code will execute when ng-if is true.
Now my doubt is , ng-if should be true even when name is in both upper and lower case..
<table ng-if="name=='JOhN' && name=='maRK'">
//rest of the code
</table>
Is it possible?
I have tried this using if-else
condition also.
if(name.toString()='john'){
alert('success')
}
else{
alert('failure')
}
Is it correct?
The star in ngIf is case sensitive. So make sure you spell this exactly the way they are and it was set to a condition. So it's a truly false e value.
To use a keyboard shortcut to change between lowercase, UPPERCASE, and Capitalize Each Word, select the text and press SHIFT + F3 until the case you want is applied.
upper() and . lower() string methods are self-explanatory. Performing the . upper() method on a string converts all of the characters to uppercase, whereas the lower() method converts all of the characters to lowercase.
Variables can only contain upper and lowercase letters (Python is case-sensitive) and _ (the underscore character). Hence, because we can't have spaces in variable names a common convention is to capitalize the first letter of every word after the first. For example, myName, or debtAmountWithInterest.
try,
<table ng-if="name.toLowerCase()=='john' && name.toLowerCase()=='mark'">
//rest of the code
</table>
or with angular lowercase
filter
<table ng-if="(name| lowercase) =='john' && (name | lowercase)=='mark'">
//rest of the code
</table>
I know this has been answered and accetped but I would do it with a function and then return the result of checking the name given with an array of accepted names. This way - it is easier to change the names in the future or to add other names as required.
//html
<table ng-if="checkName(name)">
//rest of the code
</table>
//js
checkName(name){
let acceptedNames = ['john','mark'];
let nameStr = name.lowerCase();
let result = false;
if(acceptedNames.indexOf(nameStr) > -1 ){result = true};
return result;
}
Better way to do is to convert both values to same case using the filter | uppercase)
and do comparision
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With