Angularjs:如何在评论栏中关闭ng-if?

Ale*_*kov 13 angularjs angular-ng-if

<div ng-if="true">visible</div>很容易,但由于ngIf甚至可以在评论中使用,</div>评论块的结束是什么?

试过,没有运气:

<!-- ng-if: true -->
....
<!-- ng-if -->
Run Code Online (Sandbox Code Playgroud)

谢谢.

Vam*_*msi 31

ng-if仅限于'A'.因此它只能用作属性,你不能在注释中使用这里是ngIf的angularjs代码

var ngIfDirective = ['$animate', function($animate) {
  return {
    transclude: 'element',
    priority: 600,
    terminal: true,
    restrict: 'A',       // --> This means restricting to Attribute
Run Code Online (Sandbox Code Playgroud)

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 -->