Ionic side menu does not refresh my page

Hi,

i have an app based on sidemenus. Each page has the same left sidemenu and a specific right sidemenu, and my app.js is done in a similar way as under here:

indent preformatted text by 4 spaces

.state('app.homepage', {
  url: "/homepage",
  cache: false,
  views: {
    'menuContent' :{
      templateUrl: "homepage.html",
	  controller: "HomepageCtrl"
    },
	'menuLeft' :{
      templateUrl: "menu_left.html",
	  controller: "HomepageCtrl"
    },
	'menuRight' :{
      templateUrl: "menu_account.html",
	  controller: "HomepageCtrl"
    }
  }
})
.state('app.login', {
  url: "/login",
  views: {
    'menuContent' :{
      templateUrl: "login.html",
	  controller: "LoginCtrl"
    }
  }
})

.state(‘app.project’, {
url: “/project/:projectid”,
cache: false,
// params: { data: {} },
views: {
‘menuContent’ :{
templateUrl: “project.html”,
controller: ‘WfeCtrl’
},
‘menuLeft’ :{},
‘menuRight’ :{
templateUrl: “menu_project.html”,
controller: “ProjectCtrl”
},
}

So, some pages have a specific right side menu.
My problem is the following:

in one page i have a refresh function (the page shows a list of objects); the refresh operation takes remote ajax data and then updates the $scope array that represents the list of objects. At the end of the $http call i have a $timeout function in which i effectively update the $scope var.

If i run the function from within the page (for example, putting a button inside that calls the refresh function) changes in data are displayed correctly (for example, if i delete one of the objects, it disappears from the page);

but, when i run the same function from the right sidemenu, the refresh function is executed, but changes in data are not displayed… i have verified that the $http gets actually called, and also that the returning json is correct… but the view does not refresh…

this is the structure of my right sidemenu:

` <ion-content class="has-header">
  <ion-list>
    <ion-item nav-clear menu-close  ng-controller="ProjectsCtrl" ng-click="refreshProjects()">
      <i class="icon ion-refresh"></i>&nbsp;&nbsp;Refresh
    </ion-item>`

The ProjectsCtrl controller is the correct one in which the refreshProjects function lives.

For now i’m using the refresh button inside the content of the page, but would like to use the right side menu for these kind of operations.

Hope i’ve explained well… Thanks in advance for you help

hi,
it could be because you have to wrap your scope variables in an object like in this example:

or I can suggest to you to do the refresh in this function inside the page controller:

$scope.$on(‘$ionicView.enter’, function () {

    $scope.refreshProjects();
});

it’s triggered when you open the view (created for the first time or loaded from cache)

I have that function in the ng-init of the view… should i put it also inside the $ionicViewEnter ?.. and wouldn’t it be fired twice when entering the page ?..

for the first solution, i do not have any ng-model, as the page shows a list of projects, but no editing and no form (which are instead in another separate view)…

thanks anyway

call it one time on $ionicView.enter

don’t understand why a same function, called by the right side menu, does all that is done when called on page, except updating the view… seems so linear to me, but…

had this same problem at well in other ionic apps… i don’t like very much using ionicview enter as i find it confusing, it’s called twice, three times, etc…

while ng-init, to me, ensures that the function is executed once when entering the page, and leaving the function available for other times i need it…

thanks for your effort, anyway

you’re welcome.
but if you can share with us your app or a similar example (in codeopen or upload it in google drive…)
It could be easier for us to come up with a solution.

Thanks haytam,

tomorrow i’ll try to put it in a codepen.

For now, thanks once again

1 Like

hey guzs i want to referesh side menu values…how could i do that…in ionic 2.
i already opened topic…