我试图用可选择和可移动的选项实现角度垫片.但问题是占位符在加载时移动到顶部.我不确定我在代码上做了什么错.请有人帮我解决这个问题.
原文链接:https://www.f2er.com/angularjs/141990.html在下面添加了GIF
我的代码是
<mat-form-field> <mat-chip-list #chipList> <mat-chip *ngFor="let keyword of keywords" [selectable]="selectable" [removable]="removable" (remove)="remove(keyword)"> {{keyword}} <mat-icon matChipRemove *ngIf="removable">cancel</mat-icon> </mat-chip> <input placeholder="Keywords" [matChipInputFor]="chipList" [matChipInputSeparatorKeyCodes]="separatorKeysCodes" [matChipInputAddOnBlur]="addOnBlur" (matChipInputTokenEnd)="add($event)" /> </mat-chip-list> </mat-form-field>
和ts是
visible: boolean = true; selectable: boolean = true; removable: boolean = true; addOnBlur: boolean = true; separatorKeysCodes = [ENTER,COMMA]; keywords= []; // At time load i need this to be empty public add(event: MatChipInputEvent): void { let input = event.input; let value = event.value; if ((value || '').trim()) { this.keywords.push(value.trim()); } if (input) { input.value = ''; } } public remove(keyword: any): void { let index = this.keywords.indexOf(keyword); if (index >= 0) { this.keywords.splice(index,1); } }
我使用了相同的代码,这些代码在材料文档上给出,但只有改变我完成的是代替加载数组值我在时间加载时传递空数组.请有人帮我解决这个问题