但是,问题是<mat-form-field>
并且<mat-checkbox>
没有垂直对齐。
如何将它们垂直对齐以继续前进?
代码如下:
<mat-card>
<mat-card-title>
Family Information
</mat-card-title>
<form [formGroup]="familyInfo">
<div fxLayout="row" fxLayoutAlign="flex-start" fxLayoutGap="40px">
<mat-form-field fxFlex="10%">
<mat-label>Contact Name</mat-label>
<input matInput>
</mat-form-field>
<mat-form-field fxFlex="10%">
<mat-label>Relation Type </mat-label>
<mat-select>
<mat-option *ngFor="let relationType of relationTypes" [value]="relationType" color="accent">
{{relationType}}
</mat-option>
</mat-select>
</mat-form-field>
<mat-form-field fxFlex="10%">
<mat-label>Gender </mat-label>
<mat-select>
<mat-option *ngFor="let gender of genders" [value]="gender" color="accent">
{{gender}}
</mat-option>
</mat-select>
</mat-form-field>
<mat-form-field fxFlex="10%">
<mat-label>Date Of Birth</mat-label>
<input matInput [matDatepicker]="dateOfBirth" formControlName="dateOfBirth">
<mat-datepicker-toggle matSuffix [for]="dateOfBirth"></mat-datepicker-toggle>
<mat-datepicker #dateOfBirth></mat-datepicker>
</mat-form-field>
<mat-checkbox formControlName="isDependent">Is Dependent</mat-checkbox>
<div fxFlex="100%"></div>
<mat-card-actions>
<button mat-raised-button color="primary" type="submit" class="align-right-button">
Save
</button>
</mat-card-actions>
</div>
我尝试使用<mat-form-field>
,但根据角度材料文档。 <mat-checkbox>
不能是<mat-form-field>
答案 0 :(得分:1)
您必须手动放置复选框。没有其他方法可以排列元素。类似align-self: center
的mat-checkbox。
请注意,mat-form-field
有一些自定义的填充/边距。因此,要拥有完美的装修,您需要检查元素并在顶部添加几个px。视字体大小而定。
希望这会有所帮助。祝你好运!