【发布时间】:2020-09-28 02:02:24
【问题描述】:
我正在使用 mat-autocomplete,由于某种原因,当我从下拉列表中选择项目时,我的功能无法正常工作,所以我认为我需要在我的选择中传递 add() 函数,但我知道它是“预期 1 个参数,但得到 0"。我不确定要通过什么。
任何建议,
add(event: MatChipInputEvent): void {
const input = event.input;
const value = event.value;
this.tagService.addTag(this.workspace.guid, 'workspace', value).subscribe((tag) => console.log("added", tag));
if ((value || '').trim()) {
this.superTags.push({tag: value.trim(), type: TagType.super});
}
if (input) {
input.value = '';
}
this.tagCtrl.setValue(null);
}
selected(event: MatAutocompleteSelectedEvent): void {
const tag = {tag: event.option.viewValue, type: TagType.super};
this.superTags.push(tag);
this.add() //I'm getting error that it expected 1 argument
if(this.input){
this.input.nativeElement.value = "";
}
this.tagCtrl.setValue(null);
var index = this.allSuperTagNames.indexOf(tag.tag);
this.allSuperTagNames.splice(index, 1);
this.mapper();
}
HTML
<mat-form-field class="form" appearance="fill">
<mat-label>Select a Super Tag</mat-label>
<mat-chip-list #chipList>
<div>
<mat-chip *ngFor="let superTag of superTags" [selectable]="selectable" [removable]="removable"
(removed)="remove(superTag)">
{{superTag.tag}}
<mat-icon matChipRemove *ngIf="removable">cancel</mat-icon>
</mat-chip>
</div>
<div>
<input matInput #input [formControl]="tagCtrl" [matAutocomplete]="auto" [matChipInputFor]="chipList"
[matChipInputSeparatorKeyCodes]="separatorKeysCodes" (matChipInputTokenEnd)="add($event)">
</div>
</mat-chip-list>
<mat-autocomplete #auto="matAutocomplete" (optionSelected)="selected($event)">
<mat-option *ngFor="let tag of filteredSuperTags | async" [value]="tag">
{{tag}}
</mat-option>
</mat-autocomplete>
</mat-form-field>
【问题讨论】:
-
请提供HTML代码以便更好地理解
-
@OAH 嗨,我刚刚上传了 HTML .. 谢谢
标签: html angular typescript angular-material angular-directive