Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to check a string is empty in angularjs

Tags:

javascript

I am checking a value in my controller.Here is my code.

var contents = atob(response.documents);
// I checked the value in contents . it is displaying ""
if(contents === ""){
 // no contents
}

the if condition is retuning false, when the contents has "" and when the contents has data. How to check condition?

like image 811
hanu Avatar asked Apr 26 '16 15:04

hanu


3 Answers

Good plain Javascript.

if(!contents){

}
like image 149
tpsilva Avatar answered Nov 12 '22 16:11

tpsilva


How about contents.trim().length === 0 ?

like image 42
Gian Marco Toso Avatar answered Nov 12 '22 15:11

Gian Marco Toso


Empty string in Javascript is falsey you can use:

if(contents){
  //has content
}else{
 //no content
}
like image 1
Revive Avatar answered Nov 12 '22 16:11

Revive