Exchange of information between controllers within the directive

I am trying to register events such as closing a window, minimize, maximize and use it inside my controller inside the content so that I can clear some things before the window closes. I just have a stupid idea with random identifiers and translation. Anything better?

Window controller

<div class="window">
   <div class="header">
      <a ng-click="minimize()">Minimize</a>
      <a ng-click="maximize()">Maximize</a>
      <a ng-click="close()">Close</a>
   <div class="content" ng-include="Controllers/someWindow.html"></div>
</div>

Controllers /someWindow.html

<div ng-controller="SomeWindowCtrl">

</div>
+4
source share
2 answers

You can wrap an element div.windowin a directive (for example, my-window) and set the controller out of it. Then in the directives inside it may be required my-windowas a parent, having received its controller as the fourth argument of the link function.

.

+4

$rootScope.$broadcast('EVENT_ID', data);

$rootScope.$on('EVENT_ID', function($event, data) {
    //event handler
});
+2

Source: https://habr.com/ru/post/1614767/


All Articles