我有一个在modalController中定义的模态 可以从其他指令调用此模态 实现这一目标的正确方法是什么?
正如我所见,sharedService是一种方法。 简而言之,
var ModalCtrl = function ($scope, $modal, $log) {
$scope.open = function () {
console.log("Open popup");
});
});
// In another or any other directive
app.directive('myDirective', [
function($scope, $document,windowService) {
return {
controller : function($scope,windowService,docsService){
//Its own controller.
},
link : function(scope,element,attars){
//Call popup controller on some event(say click) here.
// ModalCtrl.open()
},
}
});
答案 0 :(得分:0)
将open()
传递给mydirective的范围
<my-directive event="open()"></my-directive>
使用&
将行为绑定到scope.event
然后将click事件绑定到元素
restrict: 'E',
scope: {
event: '&'
},
link: function(scope, element, attrs) {
element.on('click', scope.event);
},