ng-ifتوجيه AngularJS


مثال

قم بإلغاء تحديد خانة الاختيار لإزالة قسم:

Keep HTML: <input type="checkbox" ng-model="myVar" ng-init="myVar = true">
<div ng-if="myVar">
<h1>Welcome</h1>
<p>Welcome to my home.</p>
<hr>
</div>

التعريف والاستخدام

ng-ifيزيل التوجيه عنصر HTML إذا تم تقييم التعبير على خطأ .

إذا تم تقييم جملة if إلى true ، فستتم إضافة نسخة من العنصر في DOM.

يختلف ng-ifالتوجيه عن ng-hide ، الذي يخفي عرض العنصر ، حيث يزيل التوجيه ng-if العنصر تمامًا من DOM.


بناء الجملة

<element ng-if="expression"></element>

مدعوم من قبل جميع عناصر HTML.


قيمه المعامل

Value Description
expression An expression that will completely remove the element if it returns false. If it returns true, a copy of the element will be inserted instead.