【问题标题】:Angular inputfield under another inputfield另一个输入字段下的角度输入字段
【发布时间】:2020-09-10 07:18:53
【问题描述】:

我想为网站上的每个问题创建inputfield,但inputfields 彼此相邻。我想在另一个inputfield 下创建inputfields

HTML 如下所示:

        <li *ngFor="let item of unteraufgaben; let i = index">
                <form [formGroup]='antwort'>
                    <mat-form-field>
                        <input matInput placeholder="Antwort" [type]="'text'" name="unterantwort"
                            [formControl]="antwort.get('antwort'+i)" autocomplete="off">
                    </mat-form-field>
                </form>
    </li>

网站图片如下:

【问题讨论】:

  • 你应该把 *ngFor="let item of unteraufgaben; let i = index" 在
      例如
        ...
      元素,然后你会得到每个
    • 中的每个 。传递
        然后只是一个引导类,以防止为 li 添加样式(点或其他符号)。但是您必须根据您的概念将
      放在 oyur HTML 页面顶部的主
        元素上。
  • 很高兴它有帮助。我可以将其添加为确实解决了您的问题的答案吗?

标签: html angular for-loop


【解决方案1】:

试试这个:

    <form [formGroup]="antwort">
        <ul *ngFor="let item of unteraufgaben; let i = index">
           <li class="list-unstyled clearfix">
                <mat-form-field>
                    <input matInput placeholder="Antwort" [type]="'text'" name="unterantwort" [formControl]="antwort.get('antwort'+i)" autocomplete="off">
                </mat-form-field>
          </li>
        </ul>
   </form>

如果您真的不需要无序列表,则只需此选项:

 <form [formGroup]="antwort">
    <div *ngFor="let item of unteraufgaben; let i = index">
         <mat-form-field class="clearfix">
                <input matInput placeholder="Antwort" [type]="'text'" name="unterantwort" [formControl]="antwort.get('antwort'+i)" autocomplete="off">
         </mat-form-field>
    </div>
</form>

【讨论】:

    【解决方案2】:

    &lt;input&gt; 元素之后尝试&lt;br&gt;

    【讨论】:

      【解决方案3】:

      您可以将mat-form-field 放在div 中并赋予div 样式-> display- flex, flex-direction- 列

      【讨论】:

      • 像这样?
      • 我试过这个
        但仍然没有变化
      猜你喜欢
      相关资源
      最近更新 更多
      热门标签