我有可拆卸芯片的列表:
<md-chip-list>
<md-chip *ngFor="let chip of chips; let i = index"
color="accent">
{{chip}}
<i class="fa fa-close" (click)="remove(i)"></i>
</md-chip>
</md-chip-list>但我需要在输入或文本区域中创建它们,如下例所示:
https://material.angularjs.org/latest/demo/chips
我该怎么做呢?
发布于 2017-07-20 06:03:24
Material2的md-chip没有Material1那么成熟。Material2团队正在努力添加大量的输入栏功能,你可以查看他们的latest example in github。他们可能会在beta.9版本中添加它们。
因此,现在需要手动构建带有md-input的md-chip。
下面是我可以最接近Material1的例子。
html:
<md-input-container floatPlaceholder="never">
<md-chip-list mdPrefix>
<md-chip *ngFor="let chip of chips; let i = index"
color="accent">
{{chip}}
<i class="fa fa-close" (click)="remove(i)"></i>
</md-chip>
</md-chip-list>
<input mdInput [mdDatepicker]="picker"
placeholder="Enter fruit"
[(ngModel)]="chipValue"
#chip
(keydown.enter)="add(chip.value)"
(keydown.backspace)="removeByKey(chip.value)">
</md-input-container>ts:
chipValue: string;
chips = [
'Apple',
'Orange',
'Banana',
'Mango',
'Cherry'
]
remove(item){
this.chips.splice(item, 1);
}
add(value){
this.chips.push(value);
this.chipValue = "";
}
removeByKey(value){
if(value.length < 1){
if(this.chips.length > 0){
this.chips.pop();
}
}
}https://stackoverflow.com/questions/45200931
复制相似问题