微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Primeng 下拉列表不会显示值

如何解决Primeng 下拉列表不会显示值

我遇到了一个奇怪的问题。我想从 http 请求中填充下拉列表。声明为 Agence 对象的数组填充了我后端的正确属性,但无法显示值。

<p-dropdown [options]="agences" [(ngModel)]="codeAgence" optionLabel="code" [ngModelOptions]=" 
{standalone: true}"></p-dropdown>

我在阵列上手动推送第一行,下拉列表仅显示添加的这一行,但忽略来自 http 请求的其他属性。奇怪的是,该数组在 http 请求之后确实具有正确的属性,如此屏幕截图所示

agences array

我的组件的代码在这里

interface Agence {
    name: string,code: string
}

export class Agences {
  id: string;
  label: string;
  order: string;
  code: string;

  fonctions: Fonction[];

  constructor(values: Object = {}) {
       Object.assign(this,values);
  }
}

@Component({
  selector: 'app-gestion-courrier',templateUrl: './gestion-courrier.component.html',styleUrls: ['./gestion-courrier.component.css']
})
export class GestionCourrierComponent implements OnInit {

  agences:Agence[] = [];
  listeAgences: Agences[] = [];

ngOnInit() {
  this.getAllAgences();
}

getAllAgences() {
  this.http.get(endPointAgences).subscribe((result: Agences[]) => {
  this.listeAgences = result;
  for (let i in this.listeAgences) {
    this.agences.push(this.listeAgences[i].label,this.listeAgences[i].code);
  }
})
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。