【问题标题】:AngularStrap - load template file in modal template as inner contentAngularStrap - 在模态模板中加载模板文件作为内部内容
【发布时间】:2015-08-22 00:42:55
【问题描述】:

我是 Angular-strap 和 AngularJS 的新手。我正在做一个将同时使用它们的项目。

场景

我的想法是为 Angular-strap 提供多个 Modal 模板文件(带页眉、带页眉和页脚等)。在其中一些模板中,我想加载不同的 HTML 文件,因此 Modal 模板文件可以像一个包装器。这个想法是这些不同的 HTML 文件将有自己的控制器和范围。我想在 Modal 模板文件中使用这些范围来显示特定数据,例如:标题、按钮、按钮文本等。

问题

似乎我无法同时使用 data-template-url 和 data-content-template (或者至少它在我这边不起作用)。我可以使用其中之一,例如,在下面的这种情况下,只使用了 data-template-url。

            <button type="button" class="btn btn-lg btn-danger" data-animation="am-fade-and-slide-top" data-template-url="views/mb-templates/popups/dialog-simple.html" bs-modal="modal" data-content-template="views/mb-templates/dialog-inner-content.html">Custom Modal
                <br />
                <small>(using data-template)</small>
            </button>

问题

  1. 是否可以创建我描述的场景?
  2. 如果是,如何做到这一点?

【问题讨论】:

    标签: angularjs angular-strap


    【解决方案1】:

    如果您使用 templateUrl 返回一个函数,并且在该函数中进行条件模板选择,那么应该是可能的。 Angular Directive 文档中关于“模板扩展指令”的部分有一个很好的例子。这是Template-expanding directive example's Plunker 的链接。该示例的指令代码如下所示:

    .directive('myCustomer', function() {
      return {
        templateUrl: function(elem, attr){
          return 'customer-'+attr.type+'.html';
        }
      };
    });
    

    【讨论】:

    • 是的,这个适用于纯 Angular。但我的想法是在 AngularStrap 中使用这种方法。那里的东西有点不同:)
    猜你喜欢
    • 1970-01-01
    • 2018-09-24
    • 1970-01-01
    • 2013-06-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-03-25
    • 1970-01-01
    相关资源
    最近更新 更多