Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 214
OneMoreQuestion Avatar asked Jul 10 '15 21:07

OneMoreQuestion


People also ask

What is Ngshow in angular?

The ng-show directive shows the specified HTML element if the expression evaluates to true, otherwise the HTML element is hidden.

Why do we use ng-show?

The ng-show Directive in AngluarJS is used to show or hide the specified HTML element. If the given expression in the ng-show attribute is true then the HTML element will display otherwise it hides the HTML element. It is supported by all HTML elements.


1 Answers

Change it to

<td>{{post.Keyword1}} <span ng-show = "post.Keyword2">,</span> {{post.Keyword2}} <span ng-show = "post.Keyword3">,</span> {{post.Keyword3}}</td>
like image 179
Vineet Avatar answered Oct 15 '22 01:10

Vineet