如何在 Angular 6 中显示表单控件值?

mkH*_*Hun 3 angular

我试图在 span 标签中而不是在 input 标签中显示表单控件。所以我尝试了下面的一个

<div formArrayName="genes">
    <table>
        <thead>
            <tr>
                <th>Position</th>
            </tr>
        </thead>
        <tbody *ngFor="let gene of genesControls.controls; let i = index" [formGroupName]="i">
            <td>
                <span>
                {{gene.position}} //not working
                {{position}} //not working
                {{gene.position.value}} //not working
                {{position.value}} //not working
                </span>

                <!--input formControlName="position" id="pos"> This is working-->
            </td>
        </tbody>
    </table>
</div>
Run Code Online (Sandbox Code Playgroud)

当我在 input 标签中尝试时,它正在工作,但对于 span 或其他一些标签,它不起作用,我不知道这里发生了什么,根据文档,我也尝试使用值,但出了点问题。我该如何解决这个问题?

KSh*_*ger 7

如果要访问它们的值,可以通过以下方式访问它:

     <tbody *ngFor="let gene of genesControls.controls; let i = index" [formGroupName]="i">
        <td>
            <span>{{gene.value.position}}</span>

            <!--input formControlName="position" id="pos"> This is working-->
        </td>
    </tbody>
Run Code Online (Sandbox Code Playgroud)