2

If I'm having this code below. How can I render the div(#divToRender) when clicking the button. I know there is angularJs code for hide/show. But I dont want it to be rendered until I click my button. Is that possible? //Thanks

<button>Render my div!</button

<div id="divToRender">
    Some text
</div>

1 Answer 1

4

You could use ng-if, it will render the element only if the expression is evaluated to true.

<button ng-click="showMyDiv = true">Render my div!</button>

<div id="divToRender" ng-if="showMyDiv">
    Some text
</div>

Example Plunker: http://plnkr.co/edit/jtasEuhNCghprsGZjSrh?p=preview

Also see ngIf documentation.

Sign up to request clarification or add additional context in comments.

6 Comments

thank you for the answer. How can I bind the "false/true" so it changes when I click the button?
You could use ng-click as show in the example above.
Sorry but I don't know how. Can you please give me a example? thank you
The example already in the code above, please see <button ng-click="showMyDiv = true">.
An example plunker has been included.
|

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.