![](/img/trans.png)
[英]How do I use an attribute directive inside an element directive template in angularjs?
[英]How to call a directive inside a service in template attribute in AngularJS?
以下是指令代碼和服務代碼。 如何在服務內部調用指令以及如何調用動態模板
指令代碼
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
};}
]);
將模板放在指令之外:
angular.module('TestModule').directive('mymodalwindow', function () {
return {
restrict: 'E',
templateURL: 'app/template/myTemplate.html'
};
});
MyTemplate.html:
<div class="modal-header">
<h3>{{modalOptions.headerText}}</h3>
</div>
我處在完全相同的情況下-需要模態對話框服務,並且希望以比將服務注入DOM中更多的角度方式進行操作。
我能找到的最好的辦法是有模式的服務中創建其自己的控制器,如概括這篇文章 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.