Angular中的ng-select问题:ERROR TypeError:Object(...)不是NgDropdownPanelComponent.ngOnInit(ng-select.js)中的函数

dEs*_*ZER 9 twitter-bootstrap angular2-template bootstrap-4 angular angular5

我在我的项目angular5中使用ng-select 2.0.0,就像在 这个链接中一样 ,我可以从api rest spring boot获得结果,但是当我点击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)
Run Code Online (Sandbox Code Playgroud)

而且我也不能选择我想要的信息(在这种情况下属性'nom'),就像ng select被阻止或者像这样的东西.

这是我的project.component.html代码

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

</ng-select>

<p>
  Selected city ID: {{selectedPersonId | json}}
</p>
Run Code Online (Sandbox Code Playgroud)

这是文件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 ');
       })

  }

}
Run Code Online (Sandbox Code Playgroud)

有帮助吗?

Rit*_*Dey 24

(只需复制粘贴我的评论中的答案即可结束问题)

我想,ng-select v2.0.0有这个问题.我在GitHub回购中找到了2个问题请求.

解决方法:

尝试将版本降级到v1.4.1.

npm uninstall @ng-select/ng-select 
npm i -s @ng-select/ng-select@1.4.1
Run Code Online (Sandbox Code Playgroud)

编辑:(25.05.18)

有问题是要改变Rxjs 6.0.如果您使用Angular v5安装ng-select v1.x或安装ng-select v2.0+使用rxjs-compat.

npm i -s @ng-select/ng-select@1.x
//or
npm i -s @ng-select/ng-select@latest rxjs-compat
Run Code Online (Sandbox Code Playgroud)

  • 我将该版本降级到v1.4.1,并且效果很好^^ (2认同)