A
A
Andrey Goncharuk2016-11-30 17:10:21
Angular
Andrey Goncharuk, 2016-11-30 17:10:21

How to link two directives?

There are two directives, the first is a menu and the second is a pop-up window, on click on the first one:

<navigation show =' modalShown'></navigation>
<menu-setting show = 'modalShown'></menu-setting>

app.directive('navigation', function(){
      return {
        restrict: 'E',
        scope: {
          show: '=',
        },
        replace: true,
        transclude: true,
        link: function (scope) {
          scope.toggleModal = function(index) {
            scope.show = true;
          };
        },
        template: 
                '<div class="exp">'+
                    '<div ng-repeat="test in model">'+
                        '<div class="title" ng-click="toggleModal()">'+
                        '</div>'+
                    '</div>'+
                '</div>'
      };
    });

app.directive('menuSetting', function() {
      return {
        restrict: 'E',
        scope: {
          show: '='
        },
        replace: true,
        transclude: true,
        link: function(scope, element, attrs) {
          scope.hideModal = function() {
            scope.show = false;
          };
        },
          template: 
                  '<div>'+
                      '<div class="nmodal" ng-show="show" ng-repeat="test in model">'+
                          '<div class="modal-overlay" ng-click="hideModal()"></div>'+
                          '<div class="modal-dialog">'+
                              '<div class="ng-modal-dialog-content" ng-transclude>'+
                              '</div>'+
                          '</div>'+
                      '</div>'+
                  '</div>'
                  };
      });

The problem is, due to the fact that menu items and pop-up windows are created through ng-repeat and when you click on any of the items, all pop-up windows are called, but you need a window with the corresponding index value to pop up by the menu index value.
How can this be done without resorting to combining directives into one?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
SirMustache, 2016-11-30
@SirMustache

https://docs.angularjs.org/guide/directive#creatin...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question