Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/32.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 以角度反应形式将值作为字段形式值的前缀_Angular_Angular Material - Fatal编程技术网

Angular 以角度反应形式将值作为字段形式值的前缀

Angular 以角度反应形式将值作为字段形式值的前缀,angular,angular-material,Angular,Angular Material,我正在使用matPrefix将值作为电话号码的前缀 <mat-form-field> <mat-label>{{ 'MOBILE' | translate }}</mat-label> <span matPrefix>05&nbsp;</span> <input type="tel" matInput placeholder="67000020" maxlen

我正在使用matPrefix将值作为电话号码的前缀

<mat-form-field>
    <mat-label>{{ 'MOBILE' | translate }}</mat-label>
    <span matPrefix>05&nbsp;</span>
    <input type="tel" matInput placeholder="67000020" maxlength="8" dir="ltr" formControlName="MobileNo">
</mat-form-field>
我希望前缀是从表单发送的电话号码值的一部分

现在,我在保存数字时添加了“05”,在编辑表单时删除了前缀

我想以多种形式使用手机号码字段。我认为单独使用组件似乎是一种过分的做法


是否有更好的方法在表单字段中添加前缀值,而不是在保存/编辑时追加/切片前缀值?

如果在表单字段中进行更多自定义操作,最好添加单独的组件。但如果你想尝试另一件事,你可以在下面尝试

<ng-template #inputWithPrefix >
       <mat-label>{{ 'MOBILE' | translate }}</mat-label>
       <span matPrefix>05&nbsp;</span>
       <input type="tel" matInput placeholder="67000020" maxlength="8" dir="ltr" formControlName="MobileNo">
</ng-template>

{{“移动的”|翻译}
05
然后你可以像下面这样使用它

<ng-template [ngTemplateOutlet]="inputWithPrefix"></ng-template>
 <ng-template #inputWithPrefix let-placeHolderVal="placeHolderVal">
  {{ placeHolderVal }}
 </ng-template>

您也可以在这里传递参数,如下所示

<ng-template [ngTemplateOutlet]="inputWithPrefix"></ng-template>
 <ng-template #inputWithPrefix let-placeHolderVal="placeHolderVal">
  {{ placeHolderVal }}
 </ng-template>

{{placeholder val}}

按照此URL获取有关ng模板和模板出口的更多详细信息

如果您在那里做更多自定义工作,最好添加单独的组件。但如果你想尝试另一件事,你可以在下面尝试

<ng-template #inputWithPrefix >
       <mat-label>{{ 'MOBILE' | translate }}</mat-label>
       <span matPrefix>05&nbsp;</span>
       <input type="tel" matInput placeholder="67000020" maxlength="8" dir="ltr" formControlName="MobileNo">
</ng-template>

{{“移动的”|翻译}
05
然后你可以像下面这样使用它

<ng-template [ngTemplateOutlet]="inputWithPrefix"></ng-template>
 <ng-template #inputWithPrefix let-placeHolderVal="placeHolderVal">
  {{ placeHolderVal }}
 </ng-template>

您也可以在这里传递参数,如下所示

<ng-template [ngTemplateOutlet]="inputWithPrefix"></ng-template>
 <ng-template #inputWithPrefix let-placeHolderVal="placeHolderVal">
  {{ placeHolderVal }}
 </ng-template>

{{placeholder val}}

按照此URL获取有关ng模板和模板出口的更多详细信息

我不认为组件是一种过度使用,我想不出任何其他好方法我不认为组件是一种过度使用,我想不出任何其他好方法