如何将json对象绑定到有角度的物质形式

时间:2018-08-20 07:43:58

标签: json angular angular-material bind

我目前正在使用带有给我的json文件的angular框架制作一个简单的表单。 json内有一些数组和对象。好吧,我成功绑定了json数组。我现在的问题是我不知道该如何使用json对象。我无法将json文件中所述的列绑定到我的表单,而是在UI中显示了列数。我已经尝试过使用ngFor,但是错误提示ngFor仅支持绑定到数组等可迭代对象。我实际上对角和这种角材料不熟悉。任何帮助将不胜感激

以下是我正在制作的表格。用红色圈起来的数字应该是列。 enter image description here

这是json文件。用红色包围的json对象是我要在表单中绑定的列 enter image description here

这是我的app.component.html。我确实认为这是我的错误所在 enter image description here

这就是我对专栏的意思。如你看到的。项目1和项目1A在两列中。项目2仅在一栏中 enter image description here

1 个答案:

答案 0 :(得分:0)

您不需要colums字段值。您可以简单地将display: flex用作<section>

<section style="display:flex; justify-content: space-between;" class="section" *ngFor="let inputSection of inputs.sections">
    <div class="section-content" *ngFor="let field of inputSection.fields; let i = index;">
        [...]
    </div>
</section>