【发布时间】:2021-07-16 14:42:49
【问题描述】:
我试图使用 ngmodel 绑定 ng-multiselect-drowdown 中的选定项目,但出现错误并且绑定不起作用。 “ERROR 错误:如果在表单标签中使用 ngModel,则必须设置名称属性或表单。控件必须在 ngModelOptions 中定义为‘独立’。”
我错过了什么吗?谢谢。
html
<div class="form-group">
<input type="text" name="screenLibName" class="form-control" placeholder="*Type in Screen Library Name" [(ngModel)]="input.screenLibName" required maxlength="30"/>
<ng-multiselect-dropdown
[placeholder]="'Select from Source Library'"
[data]="existingGuideLib"
[(ngModel)]="selectedSourceLibs"
[settings]="dropdownSettings"
(onSelect)="onItemSelect($event)"
(onSelectAll)="onSelectAll($event)"
></ng-multiselect-dropdown>
</div>
ts
existingGuideLib:GuideLibrary[] = [];
public selectedSourceLibs: any = [];
dropdownSettings: IDropdownSettings;
ngOnInit(): void {
this.resetForm();
this.dropdownSettings = {
singleSelection: false,
idField: 'ID',
textField: 'Name',
selectAllText: 'Select All',
unSelectAllText: 'UnSelect All',
itemsShowLimit: 5,
allowSearchFilter: true
};
this.guideLibService.getAllGuideLib().subscribe(
data => {
console.log(data);
this.existingGuideLib = data;
},
error => {
console.log(error.message);
this.openDialog("Failed to get existing projectID: " + error.message);
}
)
}
onItemSelect(item: any) {
}
onSelectAll(items: any) {
console.log(items);
}
【问题讨论】:
-
使用 [formControl] 而不是 [(ngModel)]
标签: angular ng-multiselect-dropdown