1 回答

TA貢獻1821條經(jīng)驗 獲得超6個贊
您可以嘗試使用管道進行修整
?import { Pipe, PipeTransform } from '@angular/core';
? ?@Pipe({
? ? ? name: 'trim',
? ? ? pure: false
? ?})
? ??
? ?export class TrimPipe implements PipeTransform {
? ? ? transform(value: string): any {?
? ? ? ? return value.trim()
? ? ? }
? ? ??
? ? }
在 html 中 {{source | trim }}
不要忘記添加app.modules declarations此管道。
ngModel分配給參數(shù)不起作用。所以你需要刪除trim()并使ngModel你的value修剪
<div class="col-2">
? ? <mat-form-field>
? ? ? ? ? ? <mat-select
? ? ? ? ? ? ? ? ? ? placeholder="Source"
? ? ? ? ? ? ? ? ? ? [(ngModel)]="applicable.SourceNm">
? ? ? ? ? ? ? ? ? ? <mat-option
? ? ? ? ? ? ? ? ? ? ? ? ? ? *ngFor="let source of applicableLevel.SourceListTxt.split(',')"
? ? ? ? ? ? ? ? ? ? ? ? ? ? [value]="source | trim">
? ? ? ? ? ? ? ? ? ? ? ? ? ? {{source | trim }}
? ? ? ? ? ? ? ? ? ? </mat-option>
? ? ? ? ? ? </mat-select>
? ? </mat-form-field>
</div>
添加回答
舉報