Strings comparison not working
Published in
2 min readAug 27, 2019
Recently, I’m working with typescript angular 7. I try to compare textbox value with some string variabels
text1 = new FormControl("");
String a ="bla";............//Somewhere on my coding universeif(this.text1.value == a){
alert(“Textbox value same as a”);
}else{
alert(“Textbox value not same as a”);
}
the result is “Textbox value not same as a”.
I also try
if(this.text1.value.toString() == a){
alert("Textbox value same as a");
}else{
alert("Textbox value not same as a");
}
the result is “Textbox value not same as a”.
And also try again
if(this.text1.value.toString().toUpperCase() == a.toUpperCase()){
alert("Textbox value same as a");
}else{
alert("Textbox value not same as a");
}
the result is “Textbox value not same as a”.
And also try again!!!!!
if(this.text1.value.match(a)){
alert("Textbox value same as a");
}else{
alert("Textbox value not same as a");
}
the result is “Textbox value not same as a”.
if(this.text1.value.trim() == a){
alert("Textbox value same as a");
}else{
alert("Textbox value not same as a");
}
The result is “Textbox value same as a”