I have the following issue :
$scope.creneaux1=creneauxFactory.list(); console.log($scope.creneaux)
gives me what i expect :
Object {}
and inside the object
creneaux : Arrays[35] inscriptions : Arrays[554]
etc..
Whenever i try to acess te inscriptions arrays with
console.log($scope.creneaux.inscriptions) console.log($scope.creneaux.inscriptions[0]) console.log($scope.creneaux["inscriptions"])
I got undefined.
How can i do ?
Factory part thats is used therefore :
var creneaux ={}, urlphp = "http://bacly.fr/baclymphp/", phpFiles = { getCreneaux: "getCreneaux.php", getInscriptionsclub: "getInscriptionsclub.php", getUsers: "getUsers.php" }, countResponse=0; function getDate(from, onSuccess, onError) { $http.get(urlphp + from).then(function (response) { if (response) { if (onSuccess) { onSuccess(response) } } else if (onError) { onError() } }, function () { onError(); } ) } getDate(phpFiles.getCreneaux, function (response) { creneaux.creneaux = response.data; countResponse++; }, function () { alert("pas d acces reseau"); }); getDate(phpFiles.getInscriptionsclub, function (response) { creneaux.inscriptions = response.data; countResponse++; }, function () { alert("pas d acces reseau"); }); getDate(phpFiles.getUsers, function (response) { creneaux.users = response.data; countResponse++; }, function () { alert("pas d acces reseau"); }); return { getResponseAfterSuccess: function (onSuccess, onError) { if (Object.keys(phpFiles).length == countResponse) { if (onSuccess) onSuccess(tournois); } else { if (onError) onError(tournois); } }, list: function(){ return creneaux; }, listinsc: function(){ return creneaux.inscriptions; }, findcreneau: function(cid){ return _.find(creneaux.creneaux, function(t) {return t.creneau_id === cid}); }, findinscription: function(cid){ return _.filter(creneaux.inscriptions, function(t) {return t.inscriptions_uid == cid}); },
UPDATE : i tried to improve my code but when i use for example :
$scope.selectedinscription=creneauxFactory.findinscription(window.localStorage.getItem('logmbaclyuid'));
i get an empty array. How to proceed to wait for data to be available ?
console.log($scope.creneaux[0]);
$scope.creneaux.creneaux.inscriptions
?console.log
in your code, and where your$scope.creneaux
object is being populated with the two arrays. But seems to me like you are trying to doconsole.log($scope.creneaux.inscriptions)
before it is available.