AngularJS ng-if 指令
定义和用法
如果表达式的计算结果为 false,ng-if
指令将删除 HTML 元素。
如果 if 语句的计算结果为 true,则该元素的副本将添加到 DOM 中。
ng-if
Directive with ng-hide
Differentng-hide
Hide the display of the element, where ng-if
The directive will completely remove the element from the DOM.
Instance
Uncheck the checkbox to delete part:
Keep HTML: <input type="checkbox" ng-model="myVar" ng-init="myVar = true"> <div ng-if="myVar"> <h1>Bayanin</h1> <p>Bayanin nan, wakilci.</p> <hr> </div>
Syntax
<element ng-if="expression</element>
All HTML elements support.
Parameter
Parameter | Description |
---|---|
expression |
Tana yin false, za a yanci abin da a yi aiki. Tana yin true, za a tura ɗan takaitaccen abin da a yi aiki. |