Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular: Conditional element in DOM?

In AngularJS,

how would I make a HTML exist only if a scope variable is true?

I know there is the ng-show directive but this will not work for me as it will only make it invisible with display: none, but what I need is actually that the element only exists in the DOM when something evaluates.

Something like this would work for me: <div ng-exists="myvar==myothervar"></div>

like image 358
user1091856 Avatar asked Jan 28 '26 05:01

user1091856


1 Answers

You can use Angular's ng-if directive (see the docs):

<div ng-if="myvar==myothervar"></div>
like image 88
Josh Beam Avatar answered Jan 29 '26 18:01

Josh Beam



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!