英文:
Angular Material Form Input messed up
问题
我的表单框出现问题:
我从Material的网站上复制了完全相同的代码:
<mat-form-field appearance="fill" floatLabel="always">
<mat-label>最低价格</mat-label>
<input matInput type="number" class="example-right-align" placeholder="0" name="minPrice" [(ngModel)]="userParams.minPrice">
<span matTextPrefix>$ </span>
<span matTextSuffix>.00</span>
</mat-form-field>
<mat-form-field appearance="fill" floatLabel="always">
<mat-label>最高价格</mat-label>
<input matInput type="number" class="example-right-align" placeholder="0" name="maxPrice" [(ngModel)]="userParams.maxPrice">
<span matTextPrefix>$ </span>
<span matTextSuffix>.00</span>
</mat-form-field>
英文:
I copied the exact code from Material's site:
<mat-form-field appearance="fill" floatLabel="always">
<mat-label>Min Price</mat-label>
<input matInput type="number" class="example-right-align" placeholder="0" name="minPrice" [(ngModel)]="userParams.minPrice">
<span matTextPrefix>$&nbsp;</span>
<span matTextSuffix>.00</span>
</mat-form-field>
<mat-form-field appearance="fill" floatLabel="always">
<mat-label>Max Price</mat-label>
<input matInput type="number" class="example-right-align" placeholder="0" name="maxPrice" [(ngModel)]="userParams.maxPrice">
<span matTextPrefix>$&nbsp;</span>
<span matTextSuffix>.00</span>
</mat-form-field>
The example on the official website shows that it should look like this:
答案1
得分: 1
问题出在您的matTextPrefix
和matTextSuffix
。尝试这样做:
<mat-form-field appearance="fill" floatLabel="always">
<mat-label>最低价格</mat-label>
<input matInput type="number" class="example-right-align" placeholder="0" name="minPrice" [(ngModel)]="userParams.minPrice">
<span matPrefix>$ </span>
<span matSuffix>.00</span>
</mat-form-field>
<mat-form-field appearance="fill" floatLabel="always">
<mat-label>最高价格</mat-label>
<input matInput type="number" class="example-right-align" placeholder="0" name="maxPrice" [(ngModel)]="userParams.maxPrice">
<span matPrefix>$ </span>
<span matSuffix>.00</span>
</mat-form-field>
英文:
The problem is with your matTextPrefix and matTextSuffix. Try this:
<mat-form-field appearance="fill" floatLabel="always">
<mat-label>Min Price</mat-label>
<input matInput type="number" class="example-right-align" placeholder="0" name="minPrice" [(ngModel)]="userParams.minPrice">
<span matPrefix>$&nbsp;</span>
<span matSuffix>.00</span>
</mat-form-field>
<mat-form-field appearance="fill" floatLabel="always">
<mat-label>Max Price</mat-label>
<input matInput type="number" class="example-right-align" placeholder="0" name="maxPrice" [(ngModel)]="userParams.maxPrice">
<span matPrefix>$&nbsp;</span>
<span matSuffix>.00</span>
</mat-form-field>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论