que
que

Reputation: 188

ion side menu, make it update once content change

I have an app made with ionic-framework.

I have a button that makes a user follow another user. The button posts to the API and it saves.

In the ion side menu, I list all the people I follow, which I get from the same API.

However, when I follow another user, the ion side menu doesn't update as it is cached I suppose. How do I make it update once I follow another user?

Thank you.

Users profile controller

$scope.toggleFollow = function(bool)
{
   $http.post('http://localhost:26264/api/follow?userId=' +$stateParams.userId +"&toggleFollow=" +bool);
}

Left menu controller

 $http.get('http://localhost:26264/api/follow').then(function(resp) {
    console.log('Success', resp);
    $scope.alternatives = resp.data;

Then I just loop out the $scope.alternatives in the left menu like

<ion-item ng-repeat="alternative in alternatives" href="#/app/user/{{ alternative.id }}">
      {{alternative.name}}
</ion-item>

Upvotes: 0

Views: 515

Answers (1)

aorfevre
aorfevre

Reputation: 5064

You need to update $scope.alternatives

For that, as we don't know your logic and code.

You can do the following :

Solution 1: Creating an event emiter & receiver :

From first controller : you can $rootScope.$broadcast("myEvent",{info : myNewAlternativesInfo}); From Second Controller : $scope.$on("myEvent",args){ //update as needed alternatives with access to args.info

Solution 2: access to data from a service

Both controller update and access to values from a shared Service Then you just need to add on your second controller a watcher on the desired value to check when it updated $scope.$watcher

If that's not enough to lead you to solution, gives us more info ;)

Upvotes: 2

Related Questions