@Muazam wrote:
Hey, I'm new with Ionic and AngularJS.
I've been experimenting a bit and found a way to share data between the controller using service.
The only problem I have is that, the data appears slow!
The "SERVICE RAN" runs once as expected, but when I change to another page(template) I expect it to load instantly not taking 1-3 second to load up with the data.So Imagine I open members.html, the service will run and get the data from my server.
And when I go to member.html, the "SERVICE RAN" doesnt run again, but the data takes like 1-3 seconds to fill the template.Is this normal or I'm doing something wrong? Thanks
In app.js my service
.factory('MemberService',function($http) { console.log("SERVICE RAN"); return { getMembers: function() { return $http.get('/api'+'/members.php'); } } })
In controller.js
Members Controller
.controller('MembersCtrl', function($scope, MemberService) { $scope.members = []; var promise = MemberService.getMembers(); promise.then( function(response) { $scope.members = response.data; console.log($scope.members); }, function(errorPayload) { console.log('failure loading members'); }); console.log($scope.members); })
Member Controller
.controller('MemberCtrl', function($scope, $stateParams, MemberService) { $scope.members = []; $scope.member = []; $scope.sid = $stateParams.playlistId; console.log($scope.sid); var promise = MemberService.getMembers(); promise.then( function(response) { $scope.members = response.data; $scope.member = $scope.members[$scope.sid]; console.log($scope.members[$scope.sid]); }, function(errorPayload) { console.log('failure loading members'); }); })
Posts: 1
Participants: 1