11

I like a directive that conditionally puts a tag outside some content (but always prints the content), like this:

<p><strong ng-if-always-keep-inner-content="model.condition">{{model.text}}</strong>/p>

so if condition is true I get

<p><strong>yada yada</strong></p>

otherwise I get

<p>yada yada</p>

I could write it myself, but I want to know if it is possible to do with built in directives/options.

I should perhaps say this is used together with Bootstrap, which afaiu recommends using <strong> vs some class with a bold font.

joeriks
  • 3,382
  • 8
  • 32
  • 42

1 Answers1

7

I don't think there is a built in directive. You should write it.

I suggest to use a classic ng-if

<p ng-if="model.condition"><strong>{{model.text}}</strong></p>
<p ng-if="!model.condition">{{model.text}}</p>

In your specific case, you can also use ng-class and set the strong style via css.

Davide Icardi
  • 11,919
  • 8
  • 56
  • 77
  • 2
    Thanks, yea. The reason for not using ng-class is simply b/c bootstrap recommends the tag, and I thought it'd be good to not add a cssrule for the same thing. So I think it could be a useful directive - "optional outer tag". – joeriks Oct 11 '13 at 08:45