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

前端之家收集整理的这篇文章主要介绍了在Angular5问题中的ng-select:ERROR TypeError:Object(…)不是NgDropdownPanelComponent.ngOnInit(ng-select.js)中的函数前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我在我的项目angular5中使用ng-select 2.0.0,如 this link所示
,我可以从api休息弹簧启动得到结果,但我正在解决一个问题我得到这个错误,而我点击ng-select:
  1. ERROR TypeError: Object(...) is not a function
  2. at NgDropdownPanelComponent.ngOnInit (ng-select.js:1450)
  3. at checkAndUpdateDirectiveInline (core.js:12352)
  4. at checkAndUpdateNodeInline (core.js:13876)

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

这是我的project.component.HTML代码

  1. <ng-select *ngIf="_listClients"
  2. [items]="listClient"
  3. bindLabel ="nom"
  4. bindValue ="id"
  5. [(ngModel)]="selectedPersonId">
  6.  
  7. </ng-select>
  8.  
  9. <p>
  10. Selected city ID: {{selectedPersonId | json}}
  11. </p>

这是文件project.component.ts

  1. import {Component,OnInit,ViewChild} from '@angular/core';
  2. import {ActivatedRoute,Router} from '@angular/router';
  3. import {ProjetService} from '../../../../../service/projet.service';
  4. import {Projet} from '../../Models/Projet';
  5. import { ModalDirective } from 'ngx-bootstrap/modal';
  6. import 'rxjs/add/operator/map';
  7. import {ClientService} from '../../../../../service/client.service';
  8.  
  9. @Component({
  10. selector: 'app-projects',templateUrl: './projects.component.html',styleUrls: ['./projects.component.scss']
  11. })
  12. export class ProjectsComponent implements OnInit {
  13.  
  14. selectedPersonId:number = null;
  15. _listClients :any;
  16.  
  17.  
  18. constructor(private router:Router,private projetSevice:ProjetService,private clientServ:ClientService,private route: ActivatedRoute) { }
  19.  
  20. ngOnInit() {
  21.  
  22. this.clientList();
  23. }
  24.  
  25.  
  26. get listClient() {
  27. return this._listClients ? this._listClients.map(item => {
  28. return {id: item.id,prenom : item.prenom,nom : item.nom}
  29. }) : [];
  30. }
  31.  
  32.  
  33. clientList(){
  34.  
  35. this.clientServ.getListClients()
  36. .subscribe((data:any)=>{
  37. this._listClients=data;
  38. },err=>{
  39. console.log('this is error ');
  40. })
  41.  
  42. }
  43.  
  44. }

有帮助吗?

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

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

解决方法

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

  1. npm uninstall @ng-select/ng-select
  2. npm i -s @ng-select/ng-select@1.4.1

编辑:(25.05.18)

有问题是从Rxjs 6.0中断更改.如果您正在使用Angular v5 install ng-select v1.x或使用rxjs-compat安装ng-select v2.0.

  1. npm i -s @ng-select/ng-select@1.x
  2. //or
  3. npm i -s @ng-select/ng-select@latest rxjs-compat

猜你在找的Angularjs相关文章