如何在 Angular JS 中迭代一个数组

How to iterate an array in Angular JS

我在 Angular JS 中使用过滤器,但是,过滤器中显示的列表显示如下值:

[{"text":"IVA"}{"text":"IVAT0"}]

这是我进行过滤的 <DIV>

                    <div class="form-group col-md-6">
                      <label>
                        IMPUESTOS
                      </label>
                    <select ng-model="articulo.impuestos_compra" name="impuestos_compra" class="form-control input-lg" required>
                        <option value="@{{ impuestos_compra }}">@{{ impuestos_compra }}</option>
                    </select>
                    </div>

而且,这是我尝试迭代这个数组:

$scope.impuestos_venta = @json($impuestos_venta);


impuestos_compra = ['IVA' , 'IVAT0' ];
        impuestos_compra.forEach(function(impuestos_compra) {
            console.log(impuestos_compra);
        });

我希望过滤器分别显示两个选项,因此可以select使用 IVA 或 IVAT0。

你能帮帮我吗?使用 <option> 标签不是一个选项,我被要求从数据库中获取值。

谢谢。

您正在寻找 ng-options 属性

如果我理解你的情况是对的,那么你需要ngRepeat遍历HTML中的选项,然后传递选项

中的数据
// This is your array
impuestos_compra = ['IVA' , 'IVAT0' ];

现在View中的使用方法:

// iterate over the impuestos_compra and then pass it to the option
<select ng-repeat="item in impuestos_compra" class="form-control input-lg" required>
    <option value="item">{{ item }}</option>
</select>