Communicating between controllers (main ui controller and subview's controller)

Hi. For example I have this structure:

})
.config(function($stateProvider, $urlRouterProvider) {
$stateProvider

.state('menu', {
  url: "/map",
  abstract: true,
  templateUrl: "templates/menu.html",   
  controller: 'MainCtrl'   
})
.state('menu.home', {
  url: "/home",
  views: {
    'menuContent' :{
      templateUrl: "templates/gpsView.html",
      controller: 'MapCtrl'
    }
  }
})

The main controller contains buttons etc. Now I want invoke function button.ng-click from MapCtrl. How you do that? Do you share common function in services, or do some $broadcast, $on?

If you are interacting with ui-components like clicks, i would use the angular-eventsystem.

If you have something like Requests, or the need of helper functions you need in multiple controllers and services, directives, i would choose the service-approach.

In my opinion it is a more expected flow because ng-click -> triggers internally an event -> so i am working with events, if i need to inform other controllers.

1 Like

This make sense. Thank you!