Search code examples
angularjsangularjs-ng-repeatng-showangular-ng-ifangularjs-ng-show

Angular ng-show if string not empty does not work


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?


Solution

  • Change it to

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