Angular 4材料芯片占位符不能正常工作

Mun*_*abu 8 typescript angular-ui angular-material angular-material2 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>
Run Code Online (Sandbox Code Playgroud)

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);
    }
}
Run Code Online (Sandbox Code Playgroud)

我使用了相同的代码,这些代码在材料文档上给出,但只有改变我完成的是代替加载数组值我在时间加载时传递空数组.请有人帮我解决这个问题

cry*_*ker 6

它是ts文件中拼写关键字的问题.你把它定义为

  keyowords = [];
Run Code Online (Sandbox Code Playgroud)

您在html文件中引用的名称是关键字.将ts文件中的名称更改为

keywords = [];
Run Code Online (Sandbox Code Playgroud)

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


Mun*_*abu 0

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