Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ng-multiselect-dropdown - 'IDropdownSettings' only refers to a type, but is being used as a value here

I am trying to use ng-multiselect-dropdown in my angular app.

I am getting this error is VSCode when I am defining the settings:

'IDropdownSettings' only refers to a type, but is being used as a value here.ts(2693)

I have imported the module using npm i ng-multiselect-dropdown and I have defined in app.module.ts. I was following the guide here.

I this how my settings look in my 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
     }
  }
}

The error is being highlighted on this line:

    this.dropdownSettings:IDropdownSettings = {

What is causing this error? I have followed the guide, and I cannot seem to find any other documentation on this module.

like image 612
JackU Avatar asked Oct 10 '19 06:10

JackU


Video Answer


1 Answers

typing a variable is only possible at declaration:

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
     }
  }
}
like image 118
D Pro Avatar answered Sep 28 '22 03:09

D Pro