Angular ng-show if string not empty does not work
Asked Answered
C

1

11

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?

Confirmatory answered 10/7, 2015 at 21:3 Comment(0)
I
17

Change it to

<td>{{post.Keyword1}} <span ng-show = "post.Keyword2">,</span> {{post.Keyword2}} <span ng-show = "post.Keyword3">,</span> {{post.Keyword3}}</td>
Insensitive answered 10/7, 2015 at 21:7 Comment(1)
Perfecto! This is awesomeConfirmatory

© 2022 - 2024 — McMap. All rights reserved.