3

I'm hiding or showing a div when a button is clicked.

I want to change the text in the link to say "show" / "hide".

I have it working but is there a better way to change the text rather than checking for the variable on two seprate spans.

    <a ng-click="showHint = !showHint"><span ng-if="showHint">Hide</span><span ng-if="!showHint">Show</span> tips</a>

    <div ng-if="showHint">
        <p>
            Hint text Hint text Hint text Hint text 
        </p>
    </div>

2 Answers 2

6

You can use conditional operator with interpolation.

<a ng-click="showHint = !showHint">{{ showHint ? "Hide" : "Show"}}tips</a>

Fiddle

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

Comments

4

Check this, hope it works for you:

<span ng-bind="showHint ? 'Hide' : 'Show'"></span>

Complete Snippet:

<a ng-click="showHint = !showHint">
    <span ng-bind="showHint ? 'Hide' : 'Show'"></span> tips
</a>

OR

<a ng-click="showHint = !showHint">
    <span ng-bind="showHint ? 'Hide tips' : 'Show tips'"></span>
</a>

Comments

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.