Reputation: 185
I am trying to add an HTML element into a div, only after checking the condition. I tried with conditionally adding a directive and append element, but I couldn't.
Upvotes: 1
Views: 2636
Reputation: 437
You have two options: The ng-show
and the ng-if
directive:
The ng-show
directive shows or hides elements respectively by adding or removing the ng-hide
CSS class, to or from the element.
Basic example:
<div id="someDiv" class="myDivClass" ng-show="myCtrl.user.attribute == true"></div>
The ng-if
directive actually deletes and recreates the element. Note that an element with the ng-if
directive has its own scope, which is destroyed when the element is deleted from the DOM.
Basic example:
<div id="someDiv" class="myDivClass" ng-if="myCtrl.user.attribute == true"></div>
Upvotes: 2
Reputation: 2636
You may try the following:
<div>
<span ng-if="x == 1">Conditional element</span>
</div>
Upvotes: 0