I tried to implement an angular matte chip with select and delete options. But the problem is that the placeholder jumps to the top during loading. I'm not sure what I am doing with the code. Please help me solve this problem.
GIF is added below
my code
<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>
and ts is
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); } }
I used the same code that is indicated on the material document, but only the change I made, instead of loading the values ββof the array. I skip an empty array at boot time. Please help me solve this problem.
angular typescript angular-ui angular-material angular-material2
Munna
source share