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 ?
(Just copy pasting the answer from my comment to close the question)
I think,ng-select v2.0.0
has this issue. I found 2 issue request in the GitHub repo.
Try to downgrade the version to v1.4.1.
npm uninstall @ng-select/ng-select
npm i -s @ng-select/[email protected]
There issue is for breaking changes from Rxjs 6.0
. If you're using Angular v5
install ng-select v1.x
or install ng-select v2.0+
with rxjs-compat
.
npm i -s @ng-select/[email protected]
//or
npm i -s @ng-select/ng-select@latest rxjs-compat
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With