7

我正在使用AngularJS编写一个Web应用程序。用户最多可向服务器提交3个关键字。我只想在关键字之间显示逗号。Angular ng-show如果字符串不为空不起作用

例如:

如果没有关键字,则:

如果有1个关键字,则:关键字

,如果有2个关键字,则:关键字,关键字

如果有3个关键字,那么:关键字,关键字,关键字

我有以下代码:

<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> 

为什么这不起作用?

回答

13

将其更改为

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

PERFECTO!这太棒了 – OneMoreQuestion