我不知道如何从 $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/