'ng-select in Angular5 issue : ERROR TypeError: Object(...) is not a function at NgDropdownPanelComponent.ngOnInit (ng-select.js

I'm working with ng-select 2.0.0 in my project angular5 as in this link , i can get results from the api rest spring boot but i'm fascing a problem i get this error while i click on ng-select :

ERROR TypeError: Object(...) is not a function
at NgDropdownPanelComponent.ngOnInit (ng-select.js:1450)
at checkAndUpdateDirectiveInline (core.js:12352)
at checkAndUpdateNodeInline (core.js:13876)

and also i can't select the information ( in this case attribute 'nom') i want , it's like the ng select is blocked or somthing like this .

this is my code for project.component.html

<ng-select  *ngIf="_listClients"
             [items]="listClient"
              bindLabel ="nom"
              bindValue ="id"
            [(ngModel)]="selectedPersonId">

</ng-select>

<p>
  Selected city ID: {{selectedPersonId | json}}
</p>

This is the file project.component.ts

    import {Component, OnInit, ViewChild} from '@angular/core';
import {ActivatedRoute, Router} from '@angular/router';
import {ProjetService} from '../../../../../service/projet.service';
import {Projet} from '../../Models/Projet';
import { ModalDirective } from 'ngx-bootstrap/modal';
import 'rxjs/add/operator/map';
import {ClientService} from '../../../../../service/client.service';

@Component({
  selector: 'app-projects',
  templateUrl: './projects.component.html',
  styleUrls: ['./projects.component.scss']
})
export class ProjectsComponent implements OnInit {

  selectedPersonId:number = null;
  _listClients :any;


constructor(private router:Router,
              private projetSevice:ProjetService,
              private clientServ:ClientService,
              private route: ActivatedRoute) { }

ngOnInit() {

       this.clientList();
  }


get listClient() {
     return this._listClients ? this._listClients.map(item => {
      return {id: item.id, prenom : item.prenom , nom : item.nom}
    }) : [];
  }


  clientList(){

     this.clientServ.getListClients()
       .subscribe((data:any)=>{
        this._listClients=data;
       },err=>{
         console.log('this is error ');
       })

  }

}

Any help ?



Solution 1:[1]

As stated on in the readme of the repo https://github.com/ng-select/ng-select#v200:

Latest version targets Angular v6 since it uses new RxJS which has breaking changes. If you are using Angular v5 you could use ng-select v1.x or install rxjs-compat compatability package. We will support v1.x with latest bug fixes to allow easier migration. For v1.x you can refer the 1.x branch.

However using v2.0.0 with rxjs-compat didn't work for me. I am using Angular v5.2.9.

Solution 2:[2]

Below are the ng-select version you have install for the respective Angular.x

  1. if >=13.0.0 <14.0.0 - ng-select version should be v8.x
  2. if >=12.0.0 <13.0.0 - ng-select version should be v7.x
  3. if >=11.0.0 <12.0.0 - ng-select version should be v6.x
  4. if >=10.0.0 <11.0.0 - ng-select version should be v5.x
  5. if >=9.0.0 <10.0.0 - ng-select version should be v4.x
  6. if >=8.0.0 <9.0.0 - ng-select version should be v3.x
  7. if >=6.0.0 <8.0.0 - ng-select version should be v2.x
  8. if v5.x.x - ng-select version should be v1.x

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Mrvonwyl
Solution 2 Banu S