Angular ng-show if string not empty does not work

OneMoreQuestion picture OneMoreQuestion · Jul 10, 2015 · Viewed 13k times · Source

I am writing a web app using AngularJS. The user submits up to 3 keywords to the server. I would like to show commas in between the keywords only if there are enough keywords.

For example:

if there are no keywords, then:

if there is 1 keyword, then: keyword

if there are 2 keywords, then: keyword, keyword

if there are 3 keywords, then: keyword, keyword, keyword

I have the following code:

    <tr>
       <td>Keywords: </td>
       <td>{{post.Keyword1}} <span ng-show = "{{post.Keyword2}}">,</span> {{post.Keyword2}} <span ng-show = "{{post.Keyword3}}">,</span> {{post.Keyword3}}</td>
    </tr>

Why does this not work?

Answer

Vineet picture Vineet · Jul 10, 2015

Change it to

<td>{{post.Keyword1}} <span ng-show = "post.Keyword2">,</span> {{post.Keyword2}} <span ng-show = "post.Keyword3">,</span> {{post.Keyword3}}</td>