如何设置芯片输入的最大芯片数?

时间:2019-07-22 02:40:31

标签: angular angular-material

我想让用户仅使用自动完成功能在片状芯片中输入一个芯片。 我知道md-chips具有md-max-chips来设置最大芯片数。 但是我使用的是片状芯片,如何设置这样的最大芯片数量?

<mat-chip-list maxLength="1">
  :
  :
</mat-chip-list>

1 个答案:

答案 0 :(得分:1)

据我所知,您不能直接在 Dim raw As Worksheet Dim formulaSht As Worksheet Dim i as Long dim Idest as Long Set raw = ThisWorkbook.Worksheets("Raw") (I changed the worksheet formula to FormulaSht just to make differentiate it from the formula command) Set formulaSht = ThisWorkbook.Worksheets("Formula") 'instead of selecting the range define it in the loop! ' g5 is cells(5,7) ' Range("G5").Select i = 5 'I'm setting the destination row as 2 ii (feel free to change it, also you can modify the 'column number, for the below I'll match column d = 4, if you want the copied row to be the same as the pasted row than you can use the same variable for both as save the tiniest bit of memory Idest = 2 ' Set Do loop to stop when an empty cell is reached. Do Until Cells(i,7) = "" formulaSht.cells(i,7).Copy Destination:=raw.cells(Idest,4) i = i+1 Idest = Idest + 1 Loop End sub 上进行设置。您可以做的是,自己检查用户要添加的每个芯片的选定芯片数量,然后根据已添加的芯片数量决定是否添加芯片。

  

退房   this   stackblitz来自官方文档,经过修改可以解决您的问题。

我所做的就是这样(通过自动完成添加筹码时):

MatChipList

这(通过键入添加筹码时):

selected(event: MatAutocompleteSelectedEvent): void {
  if (this.fruits.length < 1) { // <-- THIS
    this.fruits.push(event.option.viewValue);
    this.fruitInput.nativeElement.value = '';
    this.fruitCtrl.setValue(null);
  } 
}

基本上,在添加任何新筹码之前,请检查已选择的筹码数量。相应地编辑代码,以上示例应涵盖两种情况(自动完成和键入)。