Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular 2/4 String Comparison with Ignore Case

I'm comparing 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>
like image 546
Felix Too Avatar asked Jul 17 '26 15:07

Felix Too


2 Answers

You should use === with toLowercase()

<div *ngIf="query?.firstName.toLowerCase() === address.foreName.toLowerCase()"></div>
like image 151
Sajeetharan Avatar answered Jul 20 '26 04:07

Sajeetharan


Use Angular pipe.

<div *ngIf="(query?.firstName | lowercase) === (address.foreName | lowercase)"></div>
like image 42
Chybie Avatar answered Jul 20 '26 03:07

Chybie



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!