2

I can't figure out how to call a directive from within a modal created with the $dialog service. That directive should also be able to see the buttons on the modal and override their ng-click action.

Here's my modal template:

<div class="modal-header">
<h1>Rechercher</h1>
</div>
<div class="modal-body">

  <search-person></search-person>

</div>
<div class="modal-footer">
  <button ng-click="close(result)" class="btn btn-primary">Close</button>
</div>

the searchPerson directive template:

<span>{{test}}</span>

the searchPerson directive itself:

angular.module('person.directives').directive("searchPerson", ['PersonService',    function (PersonService) {
return {
    restrict: "E",
    templateUrl: "person/views/searchPerson.html",
    scope: {},
    controller: 'searchPersonCtrl'
}
}]);

the searchPerson controller:

angular.module('person.controllers').controller('searchPersonCtrl', ['$scope', function ($scope) {
   $scope.test = 2;    
}]);

and finally the modal controller:

 angular.module('person.controllers').controller('DialogController', ['$scope', 'dialog', function($scope, dialog) {
    $scope.test = 2;
    $scope.close = function (result) {
       alert('modal scope');
       dialog.close($scope.test);
    };
 }]);

So how do I make the searchPerson controller and the modal controller communicate with each other ?

1 Answer 1

2

I think I went a step too far. Instead of having a template and a controller for Modal, and a directive inside, the modal is now the template for the directive. Here's the code:

<div class="modal-header">
<h1>Rechercher</h1>
</div>
<div class="modal-body">

<!-- this used to be the searchPerson directive but now the Modal and the directive are just the same directive -->
<span>{{test}}</span>


</div>
<div class="modal-footer">
   <button ng-click="close(result)" class="btn btn-primary">Close</button>
</div>
Sign up to request clarification or add additional context in comments.

1 Comment

I'm having a similar issue. Did this work for you??

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.