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

标签 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 Controller :

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

最后是模态 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);
    };
 }]);

那么如何使 searchPerson Controller 和模态 Controller 相互通信?

最佳答案

我认为我走得太远了。模式现在是指令的模板,而不是模态的模板和 Controller 以及内部指令。代码如下:

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

关于angularjs:在 ui-bootstrap 模式中使用指令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16057187/

相关文章:

css - Angular Material 和 layout-fill 最多可填充 100% 的屏幕,仅此而已

带有条件表达式的 AngularJS ng 风格

javascript - 如何以单一形式使用多个 Angular UI Bootstrap Datepicker?

javascript - 如何使用 Angular 模块 'ui-route' 在指令中查找 templateUrl 并且不会在 MVC .NET 上出现错误

javascript - 从 hh :mm:yy (24 hour) to expanded time form 开始的时间转换

javascript - Angular - 使用 httpBackend 测试 http 服务会引发意外异常

javascript - 刷新页面后过滤器不起作用

javascript - 单击 ng 时附加模板

javascript - $scope.$watch 没有在指令中被触发

javascript - 如何通过AngularJS中的外部指令显示ng-repeat中隐藏的项目?