0

I have this html snippet:

<div class="principal-page">
    <p class="main-chart" 
        ...
        <i class="fa fa-bolt"></i> {{$ctrl.voltage}}
    </p>
</div>

I want to show the icon and the text only when $ctrl.voltage is present (has at least on character).

Now, even without a string it shows the icon no matter what.

Any ideas to do this?

2
  • 4
    I think you're missing a tag here. I guess AngularJS? Commented Nov 20, 2017 at 14:19
  • If this is AngularJS, are you just looking for something like the ng-show or ng-hide directive? Commented Nov 20, 2017 at 14:20

2 Answers 2

4

You are looking for ngIf:

<i ng-if="$ctrl.voltage"></i>

The icon above will only render in the DOM if the ngIf expression evaluates to a "truthy" value.

If you still want the <i> to exist in the DOM but be hidden with CSS, you can use ngHide and ngShow like so:

<i ng-hide="!$ctrl.voltage"></i>
<i ng-show="$ctrl.voltage"></i>

For further reading:

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

Comments

0

I guess in your controller you have a property like:

$scope.voltage = "some text";

Then you can use:

<i ng-if="voltage.length > 0"></i>

Or:

<i ng-show="voltage.length > 0"></i>

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.