I'm paring a number of fields in an Angular 2
template and it works for same case
properties but returns false
for the same string on different cases. Is there a way to make it case insensitive
perhaps through a simple pipe
?
<div *ngIf="query?.firstName == address.foreName"></div>
I'm paring a number of fields in an Angular 2
template and it works for same case
properties but returns false
for the same string on different cases. Is there a way to make it case insensitive
perhaps through a simple pipe
?
<div *ngIf="query?.firstName == address.foreName"></div>
Share
Improve this question
edited Jan 24, 2018 at 16:11
Felix Too
asked Jan 24, 2018 at 16:08
Felix TooFelix Too
11.9k5 gold badges26 silver badges25 bronze badges
1
- Possible duplicate of JavaScript case insensitive string parison – Supamiu Commented Jan 24, 2018 at 16:14
4 Answers
Reset to default 8You should use ===
with toLowercase()
<div *ngIf="query?.firstName.toLowerCase() === address.foreName.toLowerCase()"></div>
Use Angular pipe.
<div *ngIf="(query?.firstName | lowercase) === (address.foreName | lowercase)"></div>
If you are doing lot of string operations in your application, I suggest using a third party library like this one -
How to install
npm install --save string
Import
var S = require('string');
Ignorecase Compare String
var isEqual = S('ignoreCase').equalsIgnoreCase('IGNORECASE')
Convert Both string into lowercase and then pare. Find the below code.
apre(){
let str1 = "Wele to Xyx World";
let str2 = "world";
if(str1.toLowerCase().includes(str2.toLowerCase())){
console.log("Found");
}else{
console.log("Not Found");
}
}