80266

angularjs: using a directive inside the ui-bootstrap modal

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 ?

Answer1:

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>

Recommend

  • Instagram search bar with selenium
  • jinja2 template not found and internal server error
  • How to convert SOAP response with xsi values to json in WSO2esb
  • Floated image with variable width and heading with background image
  • saving file generated by TCPDF
  • How to view images from protected folder with php?
  • Alternative To body {overflow:scroll;} That Will Prevent Page Jostling/Wriggling?
  • Textfile Structure (tables)
  • Play WS (2.2.1): post/put large request
  • Android fill_parent issue
  • Jetty Server not starting: Unable to establish loopback connection
  • FileReader+canvas image loading problem
  • Insert into database using onclick function
  • Deselecting radio buttons while keeping the View Model in synch
  • Optimizing database types to compact database (SQLite)
  • Why HTML5 Canvas with a larger size stretch a drawn line?
  • TFS: Get latest causes slow project reloading
  • Running a C# exe file
  • vba code to select only visible cells in specific column except heading
  • Change an a tag attribute in JavaScript based on screen width
  • Upload files with Ajax and Jquery
  • jquery mobile loadPage not working
  • Properly structure and highlight a GtkPopoverMenu using PyGObject
  • Apache 2.4 - remove | delete | uninstall
  • Warning: Can't call setState (or forceUpdate) on an unmounted component
  • Numpy divide by zero. Why?
  • php design question - will a Helper help here?
  • Cannot Parse HTML Data Using Android / JSOUP
  • AngularJs get employee from factory
  • How can I get HTML syntax highlighting in my editor for CakePHP?
  • Java static initializers and reflection
  • IndexOutOfRangeException on multidimensional array despite using GetLength check
  • Authorize attributes not working in MVC 4
  • unknown Exception android
  • Reading document lines to the user (python)
  • Observable and ngFor in Angular 2
  • How to Embed XSL into XML
  • UserPrincipal.Current returns apppool on IIS
  • Unable to use reactive element in my shiny app
  • Conditional In-Line CSS for IE and Others?