【问题标题】:clean angularjs output to plain html [closed]将 angularjs 输出清理为纯 html [关闭]
【发布时间】:2014-09-12 13:41:37
【问题描述】:

我正在关注一个试图学习角度的教程,但我得到的代码比示例中说明的更混乱的代码是否存在我需要激活/停用的标志我想生成干净的 html,以便对其他建议后处理等开放。

代码:

<ul>
<li ng-repeat="day in [1,2,3,4,5,6,7]">Name of the day: {{ ['Mon', 'Tue', 'Wed', 'Thu',   'Fri', 'Sat', 'Sun'][day-1] }}</li>
</ul>

预期输出:

<ul>
  <li>Name of the day: Mon</li>
  <li>Name of the day: Tue</li>
  <li>Name of the day: Wed</li>
  <li>Name of the day: Thu</li>
  <li>Name of the day: Fri</li>
  <li>Name of the day: Sat</li>
  <li>Name of the day: Sun</li>
</ul>

实际输出:

<ul>
  <!-- ngRepeat: day in [1,2,3,4,5,6,7] --><li ng-repeat="day in [1,2,3,4,5,6,7]" class="ng-scope ng-binding">Name of the day: Mon</li><li ng-repeat="day in [1,2,3,4,5,6,7]" class="ng-scope ng-binding">Name of the day: Tue</li><li ng-repeat="day in [1,2,3,4,5,6,7]" class="ng-scope ng-binding">Name of the day: Wed</li><li ng-repeat="day in [1,2,3,4,5,6,7]" class="ng-scope ng-binding">Name of the day: Thu</li><li ng-repeat="day in [1,2,3,4,5,6,7]" class="ng-scope ng-binding">Name of the day: Fri</li><li ng-repeat="day in [1,2,3,4,5,6,7]" class="ng-scope ng-binding">Name of the day: Sat</li><li ng-repeat="day in [1,2,3,4,5,6,7]" class="ng-scope ng-binding">Name of the day: Sun</li>
</ul>

【问题讨论】:

  • 您无需考虑输出的外观。它的行为类似于预期的输出,这确实是唯一重要的事情。
  • 正如@Yoshi 已经说过的那样,您的代码正在执行您的预期。 Angular 在内部需要这样的额外标记。你有什么问题吗?
  • 所以如果没有添加标记就无法输出?
  • 不,也没有必要这样做。
  • 您正在努力争取的 clean 代码应该是 html/js before 角度接管。不是之后。

标签: html angularjs code-cleanup


【解决方案1】:

您不必担心您的 HTML 代码在浏览器端的外观。只是因为它是针对浏览器的。您应该担心您的 HTML 部分/模板在源代码管理中的外观 - 因为这是供开发人员阅读和修改的。

此外,还有一个被广泛使用的HTML minification task,它使 HTML 代码对人眼来说更不可读。但是,同样,这是针对浏览器的 - 不用担心。

【讨论】:

  • 感谢您的输入,我知道您来自哪里,但不要相信它是黑白的,例如我正在考虑使用 Angular 的项目会为前端开发人员生成 html样式因此干净的标记是非常重要的。
  • @MitchellBray 好吧,我明白你的意思。请注意,例如,如果您打开 chrome developer toolsElements 选项卡 - 您将在那里看到格式良好的 HTML。你可以使用它,不是吗?
  • 是的,谢谢,但它不是格式,而是添加的标记,我目前正在研究在保存之前使用正则表达式处理代码,但如果 angular 有最终输出选项会很好。
猜你喜欢
  • 2013-06-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-03-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多