Problem with Pull To Refresh

Hello!

I’m having a bit of trouble getting the pull to refresh working properly. Here is part of the code that’s in my controller:

$scope.refresh = function() {

	PostService.load().then(function(data) {

		PostService.set(data.data);
		$scope.posts = PostService.get();
		$scope.$broadcast('scroll.refreshComplete');

	});

}

Basically when you refresh, it reloads the posts and sets the “posts” variable inside the PostService to whatever is returned by the load. Then $scope.posts is set to the “posts” variable inside PostService.

I don’t see any reason why this wouldn’t work with the code I have, but for some reason, when you refresh, it doesn’t actually reload the data, it just makes a copy of the current posts for 1 second and then goes back to how it was before. Doesn’t make any sense.

I have tried looking at the variable at all stages in this process and there are no problems there, it just seems that the $scope isn’t updating correctly. Can anyone see why this would be from the code I posted?

Many thanks!

You probably have a problem with “dot notation”.

See many of the posts linked here : Issue with model binding when using ionic & https://github.com/angular/angular.js/wiki/Understanding-Scopes

in your view, use data.posts. Then, in your controller do this:

$scope.data = { "posts" : [] };
$scope.refresh = function() {

	PostService.load().then(function(data) {

		PostService.set(data.data);
		$scope.data.posts = PostService.get();
		$scope.$broadcast('scroll.refreshComplete');

	});

}

Hi Calendee,

Unfortunately this didn’t work. Can you think of any other reason why this wouldn’t work as expected? Thanks!

Hmm… That’s almost always the problem. Can you setup a CodePen sample so we can experiment with it?