Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript ng如果要检查ng中的变量,请重复_Javascript_Angularjs - Fatal编程技术网

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调用的结果。有没有其他方法可以做到这一点?