【问题标题】:Suggestions for dynamically creating static angularjs templates动态创建静态 angularjs 模板的建议
【发布时间】:2015-04-04 20:19:48
【问题描述】:

我想优化我的一些 angularjs 代码库,我想通过生成优化的、有针对性的静态模板来做到这一点。理想情况下,我会动态生成这些模板,这样我只需要维护一个模板,并且该模板将生成.. 其他模板。一个快速(非常简化)的示例来消除任何混淆......

以下可用于生成 2 个静态模板

templateGenerator.html

<div>
    <!-- if args.view == true -->
      <span ng-bind="data"></span>
    <!-- else -->
      <input ng-model="data"></span>
    <!-- endif -->
</div>

模板1.html

<div>
  <span ng-bind="data"></span>
</div>

template2.html

<div>
  <input ng-model="data"></span>
</div>

有哪些不错的选择?

我正在考虑的一件事是使用 underscore.js 作为 templateGenerator.html 中的模板引擎,并在构建期间通过 grunt 任务进行渲染。

我对这种方法的主要担心是.. 混合模板引擎。我不能在templateGenerator.html 中使用 angular 作为模板处理器(至少我很确定这不起作用)。使用下划线作为templateGenerator.html 的模板引擎会使代码过于复杂吗?

【问题讨论】:

  • 使用ng-include有什么问题
  • @Chandermani 我不明白这是如何适用的......

标签: javascript html angularjs templates optimization


【解决方案1】:

下面列出了几个选项

我最终使用了 processhtml 并且对它非常满意

【讨论】:

    猜你喜欢
    • 2023-03-18
    • 1970-01-01
    • 1970-01-01
    • 2013-04-08
    • 1970-01-01
    • 2014-11-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多