ng-multiselect-dropdown - 'IDropdownSettings' 仅指一种类型,但在此处用作值

Jac*_*ckU 10 javascript angular

我正在尝试ng-multiselect-dropdown在我的 angular 应用程序中使用。

我在定义设置时收到此错误是 VSCode:

'IDropdownSettings' 仅指一种类型,但在此处用作值。ts(2693)

我已经使用导入模块npm i ng-multiselect-dropdown并在app.module.ts. 我正在按照这里的指南进行操作。

我这是我的设置在我的page.component.ts

import { IDropdownSettings } from 'ng-multiselect-dropdown'

export class VQCComponent implements OnInit {
  dropdownSettings = {};

  ngOnInit() {
     this.dropdownSettings:IDropdownSettings = {
        singleSelection: false,
        idField: 'item_id',
        textField: 'item_text',
        selectAllText: 'Select All',
        unSelectAllText: 'Unselect All',
        itemsShowLimit: 3,
        allowSeachFilter: true
     }
  }
}
Run Code Online (Sandbox Code Playgroud)

此行上突出显示了错误:

    this.dropdownSettings:IDropdownSettings = {
Run Code Online (Sandbox Code Playgroud)

是什么导致了这个错误?我遵循了指南,但似乎找不到有关此模块的任何其他文档。

小智 25

只能在声明时输入变量:

export class VQCComponent implements OnInit {
  dropdownSettings:IDropdownSettings;

  ngOnInit() {
     this.dropdownSettings = {
        singleSelection: false,
        idField: 'item_id',
        textField: 'item_text',
        selectAllText: 'Select All',
        unSelectAllText: 'Unselect All',
        itemsShowLimit: 3,
        allowSeachFilter: true
     }
  }
}
Run Code Online (Sandbox Code Playgroud)

  • 太棒了,已经解决了。为什么指南中会有“this.dropdownSettings:IDropdownSettings {}”?在以前的 Angular 版本中这可能吗? (2认同)