javascript - 如何在 AngularJS 的模板属性中调用服务内的指令?

标签 javascript angularjs angularjs-directive angularjs-service

下面是指令代码和服务代码。如何调用服务内部的指令。以及如何调用动态模板

指令代码

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>

关于javascript - 如何在 AngularJS 的模板属性中调用服务内的指令?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32134439/

相关文章:

javascript - 在 JsTestDriver 中设置 CoffeeScript 单元测试

php - 如何为 TinyMCE 下载和配置 phpimage

javascript - angularjs 奇怪的数组行为,可能与异步执行有关?

javascript - AngularJs 错误 - 未捕获错误 : [$injector:unpr]

javascript - 向 AngularJS 中的指令提供远程数据

angularjs - 一个指令内的多个方法返回

javascript - 从 vue-cli 3 : Adding script tags to App. vue 将 Vuetify 添加到项目模板会破坏应用程序吗?

php - Facebook 照片 API

javascript - 为什么 insertAdjacentHTML 将 HTML 转换为对象

AngularJS - 解释为什么嵌入范围必须是隔离范围的兄弟