如何将标签像 bootstrap 一样放在 matInput 之上

Ami*_*nos 0 angular-material bootstrap-4 angular

我正在将引导形式转换为材料形式。在下面的照片中,我希望 mat-form-field 看起来像第二个引导输入
形式

但我无法在 matInput 上获得标签

我尝试过在标签标记中使用 for 属性:

            <div class="form-group">
                <label for="paysAdresse">Pays : </label>
                <mat-form-field appearance="outline">
                    <mat-label>Pays :</mat-label>
                    <input matInput id="paysAdresse"  formControlName="pays" placeholder="pays">
                </mat-form-field>
            </div>
            <div class="form-group">
                <label for="voieAdresse">Voie : </label>
                <input id="voieAdresse" formControlName="voie" type="text" class="form-control form-control-sm" >
            </div>
Run Code Online (Sandbox Code Playgroud)

但它给了我同一行的标签和输入。我怎样才能达到想要的结果?

Vik*_*kas 5

使用 Flex 布局可以轻松实现:
使用 flex-direction: column:The flexible items are displayed vertically, as a column
将此添加到组件 CSS 文件中

.form-group{
  display: flex;
  flex-direction: column;
}
Run Code Online (Sandbox Code Playgroud)

修改后的HTML

<div class="form-group">
    <label for="paysAdresse">Pays : </label>
    <mat-form-field appearance="outline">
        <input matInput id="paysAdresse" formControlName="pays" placeholder="pays">
    </mat-form-field>
</div>
Run Code Online (Sandbox Code Playgroud)

liveDemo