We're building an Ionic app with AngularJS. This app has a menubar on top of the screen with a button to open the side/hamburger-menu and a refresh button.
The menu is in a separate HTML-file and has it's own controller which makes the current menu-item active.
In app.js the states are defined for which view has which controller.
The menubar has a refresh button in the right-top corner, but how can I make that button (which has the same controller as the menu) call a function on the scope of the controller for the current view?
You can accomplish this through events
.
Template linked to Controller A:
...
<a href="#" ng-click="refresh()">Refresh</a>
...
Controller A:
.controller('AppCtrl', function($scope, $rootScope) {
$scope.refresh = function() {
// Your refresh code
$rootScope.$emit('refreshedPressed');
}
}
Controller B:
.controller('OtherCtrl', function($scope, $rootScope) {
$rootScope.$on('refreshedPressed', function() {
// Handle the event.
});
}