Javascript ng如果要检查ng中的变量,请重复
我正在努力做到这一点Javascript ng如果要检查ng中的变量,请重复,javascript,angularjs,Javascript,Angularjs,我正在努力做到这一点 {% if collection %} <tr ng-repeat="items in collection"> <td>1</td> <td>1</td> <td>1</td> </tr> {% else %} <tr> <td colspan="3">N
{% if collection %}
<tr ng-repeat="items in collection">
<td>1</td>
<td>1</td>
<td>1</td>
</tr>
{% else %}
<tr>
<td colspan="3">No items in collection</td>
</tr>
{% endif %}
{%if集合%}
1.
1.
1.
{%else%}
集合中没有项目
{%endif%}
但是我得到一个错误,说集合变量没有定义。做这件事的正确语法是什么?试着把它全部放在角度逻辑中
<tbody ng-if="collection">
<tr ng-repeat="items in collection">
<td>1</td>
<td>1</td>
<td>1</td>
</tr>
</tbody>
<tbody ng-if="!collection || collection.length==0">
<tr>
<td colspan="3">No items in collection</td>
</tr>
</tbody>
1.
1.
1.
集合中没有项目
试试下面的代码片段
<tbody ng-if="collection.length > 0">
<tr ng-repeat="items in collection">
<td>1</td>
<td>1</td>
<td>1</td>
</tr>
</tbody>
<tbody ng-if="!collection || collection.length==0">
<tr>
<td colspan="3">No items in collection</td>
</tr>
</tbody>
1.
1.
1.
集合中没有项目
我认为您的脚本编写环境有些混乱<代码>{%…%}可能由液体模板引擎使用。因此,您需要在Liquid使用的模型中定义集合。这将与AngularJS范围中定义的集合
分开。您是否使用某种异步请求填充该变量?如果是,请尝试异步填充变量。是,集合是API调用的结果。有没有其他方法可以做到这一点?