Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Typescript .length return undefined

This issue makes me crazy ...

I have this code :

if (control.value==null||control.value == "" || control.value == " " || control.value.length != 5) {
     // do something
}

My problem : control.value.length always returns 'undefined'.

I try to use a string variable like this but the result is the same.

var curVal: string = control.value;
if (curVal==null||curVal== "" || curVal == " " || curVal != 5) {
     // do something
}

Where am I wrong ?

Edit: Precision : my control.value is not null or empty, I test with the value 59000

This code :

console.log(control.value + ' - ' + control.value.length);

log this : 59000 - undefined

EDIT 2 : Thank's you, it's solved. The problem was my control.value was a number and not a string.

like image 358
AdrienTorris Avatar asked Feb 22 '16 10:02

AdrienTorris


1 Answers

Try Like these

String(control.value).length != 5

OR

control.value.toString().length != 5
like image 157
Sajeevan Vinayakavaseerakan Avatar answered Nov 17 '22 08:11

Sajeevan Vinayakavaseerakan