angularjs:在ui-bootstrap模式中使用指令

时间:2013-04-17 10:03:29

标签: angularjs angularjs-directive angular-ui-bootstrap

我无法弄清楚如何在使用$ dialog服务创建的模式中调用指令。该指令还应该能够看到模态上的按钮并覆盖它们的ng-click动作。

这是我的模态模板:

<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>

searchPerson指令模板:

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

searchPerson指令本身:

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

searchPerson控制器:

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

最后是模态控制器:

 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);
    };
 }]);

那么如何让searchPerson控制器和模态控制器相互通信呢?

1 个答案:

答案 0 :(得分:2)

我想我走得太远了。 modal现在是指令的模板,而不是Modal的模板和控制器,以及内部的指令。这是代码:

<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>