dimanche 19 juin 2016

Undefined error in scope

Why does I get undefined error in my console with this code:

var fromDateData;

if(!util.isEmpty(formItem.fromDate)){
        fromDateData = util.tmpl('{year}-{month}-{day}',{      
        day: ("0" + formItem.fromDate.getDate()).slice(-2),
        month: ("0" + (formItem.fromDate.getMonth() + 1)).slice(-2),
        year: formItem.fromDate.getFullYear( )
    }); 
}

  console.log("customData", fromDateData);

but if I remove the if statement then it will work:

var fromDateData;


        fromDateData = util.tmpl('{year}-{month}-{day}',{      
        day: ("0" + formItem.fromDate.getDate()).slice(-2),
        month: ("0" + (formItem.fromDate.getMonth() + 1)).slice(-2),
        year: formItem.fromDate.getFullYear( )
    }); 


  console.log("customData", fromDateData);

I need to use the if statement. What did I missed because I already declared fromDateData as global variable. So it should work outside of the statement right? Please help and thanks in advance.

Aucun commentaire:

Enregistrer un commentaire