【发布时间】:2015-11-15 01:14:07
【问题描述】:
下面是指令代码和服务代码。如何在服务内部调用指令以及如何调用动态模板
指令代码
angular.module('TestModule').directive('mymodalwindow', function () {
return {
restrict: 'E',
template: '<div class="modal-header">' +
'<h3>{{modalOptions.headerText}}</h3>' +
'</div>' +
};
});
服务代码
angular.module('TestModule').service('modalService', ['$modal',
function ($modal) {
var modalDefaults = {
backdrop: true,
keyboard: true,
modalFade: true,
template://How to call the above define directive here?? 1 way is <mymodalwindow></mymodalwindow> But how to pass the directives instead of giving fixed directive name
};}
]);
【问题讨论】:
-
为什么需要从服务中调用指令?您可以将服务注入指令但不能将指令注入服务
-
我需要从控制器方法中调用modalService,它会弹出对话框模态。并且需要将服务的模板替换为其他模板。
-
将服务注入控制器。看看如何:stackoverflow.com/questions/16876748/…
标签: javascript angularjs angularjs-directive angularjs-service