I'm trying to implement a display of loading message while data is being retrieved. In the case of basic js functions, it works, but in case of using factory to retrieve data, i dont get anything displayed before the data.
example of partial :
<div Class='' ng-controller="contentsCtrl">
<div ng-show="contents.news.length" class="">
<div ng-show="isloading"><br><img src="img/loader.gif" alt="" align='center'><br><br></div>
<ul id="tournois-list" ng-show="!isloading">
<li ng-repeat="content in contents.news track by $index">
<div class="tournois ">
<div class='row'>
<span class='contents_title'>{{content.content_title}}</span>
</div>
<div class='row'>
<span class='contents_dates'>{{content.content_date | date:'dd-MMMM-YYYY'}}</span>
</div>
<div class='row'>
<span class='contents_intro'>{{content.content_intro | htmlToPlaintext}}</span>
</div>
</div>
</li>
</ul>
</div>
</div>
code for controller + factory
baclyApp.controller('contentsCtrl',function($scope,contents){
$scope.isloading=true;
$scope.contents=contents.list();
console.log($scope.contents);
$scope.isloading=false;
})
baclyApp.factory("contents",function($http,$cookies){
var urlphp="http://bacly.fr/baclymphp/";
var contents={};
$http.get(urlphp+"getContent.php").then(function(response)
{
contents.news = response.data;
})
return {
list: function(){
return contents;
}
}
})
I guess this is about the timing as controller inject the factory object, so it needs to be resolved or something like this, but i don't know how to do it on another way.
Thanks !
Update : Here the other controller i'm talking about with multiple get
baclyApp.factory("tournois",function($http,$q){
//Factory qui recupère les données de tournois et iscriptions
// var urlphp="http://localhost/cordova/mbacly/www/php/";
var tournois={};
var urlphp="http://bacly.fr/baclymphp/";
$http.get(urlphp+"getTournois.php").then(function(response)
{
tournois.tournois = response.data;
console.log(tournois);
},function(status) {
alert("pas d acces réseau")
})
$http.get(urlphp+"getTournoinscriptions.php").then(function(response)
{
tournois.inscriptions = response.data;
},function() {
alert("pas d acces réseau")
});
$http.get(urlphp+"getTournoinscris.php").then(function(response)
{
tournois.inscris = response.data;
},function() {
alert("pas d acces réseau")
});
$http.get(urlphp+"getUsers.php").then(function(response)
{
tournois.users = response.data;
},function() {
alert("pas d acces réseau")
});
return {
list: function(){
return tournois;
},
find: function(cid){
return _.find(tournois.tournois, function(t) {return t.tournois_id === cid});
},
findinscris: function(cid){
return _.filter(tournois.inscris, function(t) {return t.tournois_id == cid});
},
findusers: function(uid){
return _.filter(tournois.users, function(t) {return t.user_id === uid});
},
findusersbyname: function(name){
return _.filter(tournois.users, function(t) {return t.uname === name});
},
updateinscription: function($params){
// var urlphp="http://localhost/cordova/mbacly/www/php/";
var urlphp="http://bacly.fr/baclymphp/";
var tournois={};
var retour="retour-OK";
$params_encoded =encodeURIComponent(JSON.stringify($params));
$http.get(urlphp+"saveinscription.php?data="+$params_encoded).success(function(data){
// console.log("retour-OK"+data);
retour="retour-OK";
});
return retour;
},
insertinscription: function($params){
// var urlphp="http://localhost/cordova/mbacly/www/php/";
var urlphp="http://bacly.fr/baclymphp/";
var tournois={};
var retour="retour-OK";
$params_encoded =encodeURIComponent(JSON.stringify($params));
$http.get(urlphp+"saveinscription.php?data="+$params_encoded).success(function(data){
// console.log("retour-OK"+data);
retour="retour-OK";
});
return retour;
},
deleteinscription: function($params){
// var urlphp="http://localhost/cordova/mbacly/www/php/";
var urlphp="http://bacly.fr/baclymphp/";
var tournois={};
var retour="retour-OK";
$params_encoded =encodeURIComponent(JSON.stringify($params));
$http.get(urlphp+"saveinscription.php?data="+$params_encoded).success(function(data){
// console.log("retour-OK"+data);
retour="retour-OK";
});
return retour;
}
}
})
Controller (part of):
baclyApp.controller('tournoisCtrl',['$scope','tournois','$cookies','$state','$window','growl',function($scope,tournois,$cookies,$state,$window,growl){
//Liste des tournois
$scope.showtournoislist=true;
$scope.tournois=tournois.list();
.. and later in the controller
tournois.findinscris(cid)