2

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>

2
  • 1
    ng-if does what you want, if you are using a recent version of Angular. Commented Jun 15, 2014 at 20:03
  • Documentation Commented Jun 15, 2014 at 20:08

2 Answers 2

8

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

<div ng-if="myvar==myothervar"></div>
Sign up to request clarification or add additional context in comments.

Comments

3

https://docs.angularjs.org/api/ng/directive/ngIf

is what you are looking all over

may be what shall give you what you are looking for. Check you angular version though.

1 Comment

Exactly what I needed. Couldn't be easier. Thanks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.