Angular 4 material 筹码占位符无法正常工作

Angular 4 material chips placeholder not working properly

我试图实现 angular 具有可选和可移除选项的垫片。但问题是占位符在加载时移至顶部。我不确定我在代码上做错了什么。请有人帮我解决这个问题。

在下面添加了 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);
    }
}

我使用了 material 文档中给出的相同代码,但我所做的唯一改变是我在加载时传递空数组而不是加载数组值。请有人帮我解决这个问题

ts 文件中的关键字拼写有问题。您已将其定义为

  keyowords = [];

您在 html 文件中提到的名称是关键字。将ts文件中的名字改成

keywords = [];

这是相同的 stackblitz 代码:- https://stackblitz.com/edit/angular-rtti3v?file=app%2Fchips-input-example.html

我将 Angular 从 4.4.X 更新到最新的 5.2.2。问题得到解决。似乎 Angular 错误。