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?

Samurai Jack
  • 2,985
  • 8
  • 35
  • 58

2 Answers2

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:

Christian Santos
  • 5,386
  • 1
  • 18
  • 24
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>
Syedur
  • 414
  • 4
  • 10