Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Allow both upper case and lower case inside ng-if

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?

like image 972
laz Avatar asked Jan 08 '18 04:01

laz


People also ask

Is ngIf case sensitive?

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.

How do you toggle between upper and lower case?

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.

What is upper and lower case in string?

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.

Does upper and lower case matter in Python?

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.


3 Answers

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>
like image 129
Azad Avatar answered Oct 27 '22 21:10

Azad


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;
}
like image 2
gavgrif Avatar answered Oct 27 '22 21:10

gavgrif


Better way to do is to convert both values to same case using the filter | uppercase) and do comparision

like image 1
Sajeetharan Avatar answered Oct 27 '22 23:10

Sajeetharan