简体   繁体   English

Angular Material 6 Mat-Chip-List-两个Mat-chip-list声明共享同一数据源

[英]Angular Material 6 Mat-Chip-List - two mat-chip-list declarations share the same data source

Using Angular 6 and Angular Material, I am trying to make 2 Auto-complete Chip Lists with different data sources - I have extended the last example here at: https://material.angular.io/components/chips/overview 我试图使用Angular 6和Angular Material,使用不同的数据源制作2个自动完成的芯片列表-我在这里扩展了最后一个示例: https : //material.angular.io/components/chips/overview

However, the last Mat-Chip-List seems to "override" the previous one, even though they are mapped to different objects and tags etc. 但是,即使它们被映射到不同的对象和标签等,最后一个Mat-Chip-List似乎也“覆盖”了前一个。

If you remove the second Mat-Chip-List, the first one loads correctly - if you change the order of declaration of either Map-Chip-List , the second one always loads correctly 如果删除第二个Mat-Chip-List,则第一个将正确加载-如果更改任一Map-Chip-List的声明顺序,则第二个将始终正确加载

I have created a StackBlitz here for demo: https://stackblitz.com/edit/angular-v2jdk8 我在这里创建了一个StackBlitz进行演示: https ://stackblitz.com/edit/angular-v2jdk8

Is there a way to uniquely identify either of these? 有没有一种方法可以唯一地识别这两个方法?

The problem is that you bind both your autocompletions to the variable auto . 问题是您将两个自动完成都绑定到变量auto Find unique names and it works fine. 查找唯一的名称,效果很好。

Instead 代替

[matAutocomplete]="auto"
                  ^^^^^^

and

<mat-autocomplete #auto="matAutocomplete" (optionSelected)="selectedFruit($event)">
                  ^^^^^

do

[matAutocomplete]="fruitAuto"
                   ^^^^^^^^^

and

<mat-autocomplete #fruitAuto="matAutocomplete" (optionSelected)="selectedFruit($event)">
                  ^^^^^^^^^^

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM