Angular 角度材质:如何右对齐matInput占位符?
我有一个简单的代码:Angular 角度材质:如何右对齐matInput占位符?,angular,angular-material,Angular,Angular Material,我有一个简单的代码: <body style="direction: rtl; text-align: right"> <mat-form-field> <input matInput placeholder="Wanna be rtl" /> </mat-form-field> </body> 但不管我想做什么,占位符都是从左到右的。有没有办法将其向右对齐?在表单字段上使用文本对齐
<body style="direction: rtl; text-align: right">
<mat-form-field>
<input matInput placeholder="Wanna be rtl" />
</mat-form-field>
</body>
但不管我想做什么,占位符都是从左到右的。有没有办法将其向右对齐?在表单字段上使用
文本对齐将起作用:请参阅工作
此解决方案将占位符和输入文本向右对齐:
<body>
<mat-form-field style="text-align: right">
<input matInput placeholder="Wanna be rtl" />
</mat-form-field>
</body>
结果:
使用CDK中的模块:
import {BidiModule} from '@angular/cdk/bidi';
...
<body dir="rtl">
<mat-form-field>
<input matInput placeholder="I am RTL" />
</mat-form-field>
</body>
从'@angular/cdk/bidi'导入{BidiModule};
...
过了一段时间,我遇到了mat form字段的sas,我发现如果mat form字段的父项具有dir=“rtl”
属性,它将充当rtl:
<body dir="rtl">
<mat-form-field>
<input matInput placeholder="I am rtl" />
</mat-form-field>
</body>
<body dir="rtl">
<mat-form-field>
<input matInput placeholder="I am rtl" />
</mat-form-field>
</body>