Angular 2 Material 表单元素水平对齐

标签 angular angular-material

我想提前感谢您抽出宝贵的时间。非常感谢您的帮助!

这是我使用 Angular 2 Material Design 创建的表单。我想知道如何对齐和?正如您在下面的快照中看到的,账单编号高于年份。

enter image description here

下面是代码

<md-card class="bill-form">
<md-toolbar color="warn">
    <md-card-title>{{bill.Type}}</md-card-title>
</md-toolbar>
<md-card-content class="form-content">
    <form>
        <table style="width:100%" cellspacing="0">
            <tr>
            <td>
                <md-select placeholder="Vendor" [(ngModel)]="bill.VendorShortcut" name="VendorShorcut"
                (change)="getVendor(bill.VendorShortcut)">
                    <md-option>
                    </md-option>
                    <md-option *ngFor="let vendor of vendors" [value]="vendor">
                        {{vendor}}
                    </md-option>
                </md-select>
            </td>
            <td>
                <md-select placeholder="Type" [(ngModel)]="bill.Type" name="Type" selected="'Bill'">
                    <md-option [value]="'Bill'">
                        Bill
                    </md-option>
                    <md-option [value]="'Credit'">
                        Credit
                    </md-option>
                </md-select>

            </td>
            <td>
                <md-select placeholder="Month" [(ngModel)]="bill.Month" name="Month" selected="bill.Month">
                    <md-option *ngFor="let month of months" [value]="month">
                        {{month}}
                    </md-option>
                </md-select>
            </td>
            <td>
                <md-select placeholder="Year" [(ngModel)]="bill.Year" name="Year" selected="bill.Year">
                    <md-option *ngFor="let year of years" [value]="year">
                        {{year}}
                    </md-option>
                </md-select>
            </td>
            <td>
                <md-input-container>
                    <input mdInput placeholder="Bill Number"  [(ngModel)]="bill.BillNumber" name="BillNumber">
                </md-input-container>
            </td>
            <td>
                <md-input-container align="end">
                    <input mdInput placeholder="Amount" [(ngModel)]="bill.Total" name="Total">
                    <span md-prefix>$&nbsp;</span>
                    <span md-suffix></span>
                </md-input-container>
            </td>
            </tr>
        </table>

    </form>
</md-card-content>

最佳答案

很晚才谈到这一点,但对于使用最新 Angular Material 的人来说,您可能需要考虑放弃表格和容器并使用 Angular Material 网格列表。

<mat-grid-list>
    <mat-grid-tile class="form-tile">
        Date:
    </mat-grid-tile>
    <mat-grid-tile class="form-tile">
        <input matInput placeholder="Date"  [(ngModel)]="date" name="date">
    </mat-grid-tile>
</mat-grid-list>

您可以指定行高和列数。 此控件的 API 可在此处找到:

Grid List

如果您希望在列表中进一步设置样式,请查看这篇进一步的 S-O 帖子:

Further style your grid

在上面的示例中,您将使用类 form-tile 来进一步设计您的组件。根据我的经验,这提供了一致且整洁的表单体验。

关于Angular 2 Material 表单元素水平对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43328942/

相关文章:

Angular 本地化 : just switch language, 无需翻译

css - Angular 2 - TypeScript (.ts) 文件中的 routerLinkActive ="active"等价物是什么?

angular - *ngFor 中的条件

angular - 是否可以禁用在 cdkDrag 的子元素上拖动?

带有路由选项卡的 Angular Material Routed 对话框

angular - 当我在确认窗口中单击取消时,mat-slide-toggle 不应更改其状态

javascript - md-char-count 未在 md-input-container 中更新

javascript - Angular 中的动态子组件

Spring Security 与 Angular2

javascript - Angular :单击按钮时选择特定选项卡