gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-29 17:11:27 26 4
gpt4 key购买 nike

我在我的项目 angular5 中使用 ng-select 2.0.0 作为 this link,我可以从 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)

而且我无法选择我想要的信息(在本例中为属性“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>

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

}

}

有什么帮助吗?

最佳答案

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

我认为,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

编辑:(25.05.18)

Rxjs 6.0 的中断更改存在问题。如果您使用的是 Angular v5 安装 ng-select v1.x 或使用 rxjs- 安装 ng-select v2.0+兼容

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

关于angular - Angular5 问题 : ERROR TypeError: Object(. 中的 ng-select ..) 不是 NgDropdownPanelComponent.ngOnInit 中的函数(ng-select.js,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50316141/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com