【发布时间】: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