nick nick -4 years ago 41
MySQL Question

Error when trying an angular.forEach inside a .then() function

I receive correctly this nice array of json from my angularJs factory, from my php server-mysql backend . It is some rendez-vous with a start date:

[{"id":"1","title":"Loi Travail","infos":null,
"adresse":"12 avenue des lis 78013 paris",
"criticite":"4","fichiers":null,
"start":"2017-06-11T22:37:59.012Z"},
{"id":"17","title":"jjtyjyjt","infos":"jytjjyjyj",
"adresse":"tjtyjjyj","criticite":"7","fichiers":"",
"start":"2017-06-11T22:37:59.012Z"}]


The problem is that angular-material-datetimepicker doesn't recognise the start date, because it is a string, so i need to do a loop to add
new Date()
, for converting each of my "start" elements.

So, i've done this short code :

rdvFactory.get_rdvs().then(function(data){
console.log(data.data);

angular.forEach(data.data),function(value,index){
console.log(value.start);
}
}).finally(function(){})


BUt my console.log shows nothing, and instead i've got this strange error :


TypeError: b is undefined
Trace de la pile :
q@https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js:7:481
@http://localhost/rdvjuristes/app.js:61:2
h/<@https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js:134:467
$digest@https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js:145:417
$apply@https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js:149:111
l@https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js:102:87
wg/https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js:107:489
Possibly unhandled rejection: {}


Do you think it is related to a $q thing ? Maybe there is another way for converting the dates ?

Thank you a lot if you have an idea, have a good day.

Just for information, if i type this, then the calendar displays well the rendez -vous(Please have a look at new Date()) :

$scope.events = [{"id":"1","title":"Loi Travail","infos":null,
"adresse":"12 avenue des lis 78013 paris",
"criticite":"4","fichiers":null,
"start":new Date("2017-06-11T22:37:59.012Z")}]

Answer Source

According to docs, Change

From

 angular.forEach(data.data),function(value,index){
        console.log(value.start); 
}

To

 angular.forEach(data.data,function(value,index){
        console.log(value.start); 
 });
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download