angularjs:使用UI自举模式内部指令 [英] angularjs: using a directive inside the ui-bootstrap modal
问题描述
我无法弄清楚如何从与$对话框服务创建一个模式中调用指令。该指令也应该能够看到的模式按钮和覆盖其NG-点击动作。
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>
在searchPerson指令的模板:
the searchPerson directive template:
<span>{{test}}</span>
在searchPerson指令本身:
the searchPerson directive itself:
angular.module('person.directives').directive("searchPerson", ['PersonService', function (PersonService) {
return {
restrict: "E",
templateUrl: "person/views/searchPerson.html",
scope: {},
controller: 'searchPersonCtrl'
}
}]);
在searchPerson控制器:
the searchPerson controller:
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控制器和模态控制器相互沟通?
So how do I make the searchPerson controller and the modal controller communicate with each other ?
推荐答案
我觉得我进了一步太远。代替具有一个模板和模态控制器,和一个指令内的,模式现在是该指令的模板。这里的code:
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>
这篇关于angularjs:使用UI自举模式内部指令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!