<div ng-if="true">visible</div>
非常简单,但是因为 ngIf甚至可以在评论中使用,结束语是什么 </div>
评论区?
尝试过,但运气不佳:
<!-- ng-if: true -->
....
<!-- ng-if -->
谢谢。
最佳答案
ng-if
仅限于 'A'
。所以它只能用作属性,不能在注释中使用这是 ngIf 的 angularjs 代码
var ngIfDirective = ['$animate', function($animate) {
return {
transclude: 'element',
priority: 600,
terminal: true,
restrict: 'A', // --> This means restricting to Attribute
restrict
选项通常设置为:'E'
, 'A'
, 'C'
, 'M'
EACM
之一将指令限制为特定的指令声明样式。 If you don't restrict any, the defaults (elements and attributes) are used
.
E
- 元素名称(默认):<my-directive></my-directive>
A
- 属性(默认):<div my-directive="exp"></div>
C
- 类别:<div class="my-directive: exp;"></div>
M
- 评论:<!-- directive: my-directive exp -->
关于Angularjs:如何关闭评论 block 中的 ng-if ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23012941/