Skip to content
Advertisement

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>

Advertisement

Answer

You should use === with toLowercase()

<div *ngIf="query?.firstName.toLowerCase() === address.foreName.toLowerCase()"></div>
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement