Search code examples
angularjsonsen-uimonaca

Onsenui app add custom function on navigator click


I develop a Onsenui app on Monaca and I'd like to add a custom function on my on-right-button-click event :

<ons-navigator 
  title="MyTitlte"
  right-button-icon="fa fa-lg fa-refresh"
  on-right-button-click="refresh()"
  page="pages/msg.html">
</ons-navigator>

my refresh() function is defined in my controller

moduleApp.controller('MyCtrl', ['$scope', '$http', function ($scope, $http) { 

   // Refresh items
   $scope.refresh = function () {
    ....
   };
}]);

Thanks for your help


Solution

  • You need to set "MyController" on the navigator or above the navigator.

    <ons-navigator
      ng-controller="MyController" 
      title="MyTitlte"
      right-button-icon="fa fa-lg fa-refresh"
      on-right-button-click="refresh()"
      page="pages/msg.html">
    </ons-navigator>